flatbuffers-addon
Advanced tools
Comparing version 0.1.1 to 0.1.2
23
index.js
@@ -5,9 +5,8 @@ const addon = require('bindings')('addon.node'); | ||
const StringBuffer = str => { | ||
const buffer = Buffer.from(str); | ||
const len = buffer.length; | ||
const target = Buffer.allocUnsafe(len + 1); | ||
buffer.copy(target); | ||
target[len] = 0; | ||
return target; | ||
} | ||
const len = Buffer.byteLength(str, "utf8"); | ||
const buffer = Buffer.allocUnsafe(len + 1); | ||
buffer.write(str, "utf8"); | ||
buffer[len] = 0; | ||
return buffer; | ||
}; | ||
@@ -79,4 +78,8 @@ const schemaOptions = options => { | ||
if (typeof options.include_prefix === "string") { | ||
options.include_prefix = StringBuffer(options.include_prefix); | ||
} | ||
return options; | ||
} | ||
}; | ||
@@ -87,4 +90,4 @@ Object.assign(exports, { | ||
if (Buffer.isBuffer(options.json) && options.json_contents != null) { | ||
throw new TypeError("if json option is a Buffer, json_contents must be null or undefined"); | ||
if (options.json_contents != null && (Buffer.isBuffer(options.json) || typeof options.json === "object")) { | ||
throw new TypeError("if json option is a Buffer or an Object, json_contents must be null or undefined"); | ||
} | ||
@@ -91,0 +94,0 @@ |
{ | ||
"name": "flatbuffers-addon", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Node flatbuffers addon", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -16,5 +16,4 @@ # flatbuffers-addon | ||
Schema path. | ||
if `schema` is a String and `schema_contents` is `null` or `undefined`, `schema` will be treated as `schema_contents`. | ||
otherwise, it will be treated as the schema file path. | ||
@@ -25,3 +24,4 @@ ### options.schema_contents | ||
Schema contents. | ||
The schema contents. | ||
If the `schema_contents` is a schema binary, the `schema` file path must end with `.bfbs`. | ||
@@ -36,4 +36,2 @@ ### options.schema_length | ||
**NOT TESTED** | ||
`type: bool` | ||
@@ -44,2 +42,16 @@ `default: false` | ||
### options.json | ||
`type: String|Buffer|Object` | ||
if `json` is a String and `json_contents` is `null` or `undefined`, `json` will be treated as `json_contents`. | ||
if `json` is a Buffer or an Object, `json` will be treated as `json_contents`. | ||
otherwise `json` must be a String and will be treated as the path to the JSON. | ||
### options.json_contents | ||
`type: String|Buffer|Object` | ||
The JSON to serialize | ||
### options.include_directories | ||
@@ -104,4 +116,2 @@ | ||
**NOT TESTED** | ||
`type: bool` | ||
@@ -178,5 +188,4 @@ `default: false` | ||
Schema path. | ||
if `schema` is a String and `schema_contents` is `null` or `undefined`, `schema` will be treated as `schema_contents`. | ||
otherwise, it will be treated as the schema file path. | ||
@@ -187,3 +196,4 @@ ### options.schema_contents | ||
Schema contents. | ||
The schema contents. | ||
If the `schema_contents` is a schema binary, the `schema` file path must end with `.bfbs`. | ||
@@ -190,0 +200,0 @@ ### options.schema_length |
Sorry, the diff of this file is not supported yet
58010
585
393