Comparing version 0.1.3 to 0.1.4
13
index.js
exports.Packr = require('./pack').Packr | ||
exports.Unpackr = require('./unpack').Unpackr | ||
let unpackModule = require('./unpack') | ||
let extractor = tryRequire('./build/Release/msgpackr.node') | ||
if (extractor) | ||
unpackModule.setExtractor(extractor) | ||
exports.Unpackr = unpackModule.Unpackr | ||
exports.PackrStream = require('./stream').PackrStream | ||
@@ -9,1 +13,8 @@ exports.UnpackrStream = require('./stream').UnpackrStream | ||
function tryRequire(moduleId) { | ||
try { | ||
return require(moduleId) | ||
} catch (error) { | ||
console.warn('Native extraction module not loaded, msgpackr will still run, but with decreased performance. ' + error.message.split('\n')[0]) | ||
} | ||
} |
@@ -38,2 +38,3 @@ "use strict" | ||
target = Buffer.allocUnsafeSlow(target.length) | ||
safeEnd = target.length - 10 | ||
position = 0 | ||
@@ -396,3 +397,7 @@ } | ||
} else { | ||
recordId = structures.nextId++ || (structures.nextId = 0x40) | ||
recordId = structures.nextId++ | ||
if (!recordId) { | ||
recordId = 0x40 | ||
structures.nextId = 0x41 | ||
} | ||
if (recordId >= 0x80) {// cycle back around | ||
@@ -399,0 +404,0 @@ structures.nextId = (recordId = maxSharedStructures + 0x40) + 1 |
{ | ||
"name": "msgpackr", | ||
"author": "Kris Zyp", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Fast MessagePack implementation with extension for record structures", | ||
@@ -21,5 +21,10 @@ "license": "MIT", | ||
"dependencies": { | ||
"msgpack-lite": "^0.1.26", | ||
"nan": "^2.13.1", | ||
"prebuild-install": "^5.2.5" | ||
}, | ||
"exports": { | ||
"node": "./index.js", | ||
"browser": "./browser.js" | ||
}, | ||
"optionalDependencies": {}, | ||
@@ -26,0 +31,0 @@ "devDependencies": { |
@@ -120,3 +120,3 @@ var msgpackr = tryRequire(".."); | ||
buf = bench('require("avsc")...make schema/type...type.toBuffer(obj);', type.toBuffer.bind(type), data); | ||
obj = bench('require("avsc")...make schema/type...type.toBuffer(obj);', type.fromBuffer.bind(type), buf); | ||
obj = bench('require("avsc")...make schema/type...type.fromBuffer(obj);', type.fromBuffer.bind(type), buf); | ||
} | ||
@@ -123,0 +123,0 @@ |
@@ -1,2 +0,2 @@ | ||
var inspector = require('inspector') | ||
//var inspector = require('inspector') | ||
//inspector.open(9330, null, true) | ||
@@ -3,0 +3,0 @@ |
"use strict" | ||
let { setSource, extractStrings } = tryRequire('./build/Release/msgpackr.node') | ||
let setSource = () => {} // don't need to do anything without the native support here | ||
let decoder | ||
try { | ||
decoder = new TextDecoder() | ||
} catch(error) {} | ||
let extractStrings | ||
let src | ||
@@ -75,2 +80,6 @@ let srcEnd | ||
} | ||
exports.setExtractor = (extractor) => { | ||
setSource = extractor.setSource | ||
extractStrings = extractor.extractStrings | ||
} | ||
@@ -90,3 +99,4 @@ function read() { | ||
} else if (currentUnpackr.getStructures) { | ||
currentUnpackr.structures = currentStructures = currentUnpackr.getStructures() || [] | ||
// we have to preserve our state anytime we provide a means for external code to re-execute unpack | ||
currentUnpackr.structures = currentStructures = saveState(() => currentUnpackr.getStructures()) || [] | ||
structure = currentStructures[token & 0x3f] | ||
@@ -128,14 +138,13 @@ if (structure) { | ||
// fixstr | ||
return readFixedString(token - 0xa0) | ||
let length = token - 0xa0 | ||
if (length < 8) | ||
return simpleString(length) | ||
let string = strings[stringPosition++] | ||
if (string === undefined) { | ||
strings = readStrings(position - 1, srcEnd) | ||
stringPosition = 0 | ||
string = strings[stringPosition++] | ||
if (srcStringEnd >= position) { | ||
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart) | ||
} | ||
position += length | ||
return string | ||
if (srcStringEnd == 0 && length < 8 && srcEnd < 128) { | ||
// for small blocks, avoiding the overhead of the extract call is helpful | ||
let string = simpleString(length) | ||
if (string != null) | ||
return string | ||
} | ||
return readFixedString(length) | ||
} else { | ||
@@ -231,3 +240,7 @@ let value | ||
// str 8 | ||
return readString8(src[position++]) | ||
value = src[position++] | ||
if (srcStringEnd >= position) { | ||
return srcString.slice(position - srcStringStart, (position += value) - srcStringStart) | ||
} | ||
return readString8(value) | ||
case 0xda: | ||
@@ -289,15 +302,5 @@ // str 16 | ||
return function readString(length) { | ||
if (srcString && srcStringEnd >= position) { | ||
return srcString.slice(position - srcStringStart, (position += length) - srcStringStart) | ||
} | ||
srcString = null | ||
let string = strings[stringPosition++] | ||
if (string == null) { | ||
if (length < 8 && srcEnd < 128) { | ||
// for small blocks, avoiding the overhead of the extract call is helpful | ||
string = simpleString(length) | ||
if (string != null) | ||
return string | ||
} | ||
strings = extractStrings(position - headerLength, srcEnd) | ||
strings = extractStrings ? extractStrings(position - headerLength, srcEnd) : [decoder.decode(src.slice(position, position + length))] | ||
stringPosition = 0 | ||
@@ -452,9 +455,24 @@ string = strings[stringPosition++] | ||
} | ||
function tryRequire(moduleId) { | ||
try { | ||
return require(moduleId) | ||
} catch (error) { | ||
console.error(error) | ||
return {} | ||
} | ||
function saveState(callback) { | ||
let savedSrcEnd = srcEnd | ||
let savedPosition = position | ||
let savedStringPosition = stringPosition | ||
let savedSrcStringEnd = srcStringEnd | ||
let savedSrcString = srcString | ||
let savedStrings = strings | ||
let savedSrc = src | ||
let savedStructures = currentStructures | ||
let savedPackr = currentUnpackr | ||
let value = callback() | ||
srcEnd = savedSrcEnd | ||
position = savedPosition | ||
stringPosition = savedStringPosition | ||
srcStringEnd = savedSrcStringEnd | ||
srcString = savedSrcString | ||
strings = savedStrings | ||
src = savedSrc | ||
currentStructures = savedStructures | ||
currentUnpackr = savedPackr | ||
return value | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
88750
19
1710
4
1
3
+ Addedmsgpack-lite@^0.1.26
+ Addedevent-lite@0.1.3(transitive)
+ Addedint64-buffer@0.1.10(transitive)
+ Addedmsgpack-lite@0.1.26(transitive)