Comparing version 2.0.0 to 2.1.0
@@ -7,4 +7,4 @@ 'use strict'; | ||
class IOBuffer { | ||
constructor(data) { | ||
let length = 0; | ||
constructor(data, options) { | ||
options = options || {}; | ||
if (data === undefined) { | ||
@@ -14,10 +14,12 @@ data = defaultByteLength; | ||
if (typeof data === 'number') { | ||
length = data; | ||
data = new ArrayBuffer(data); | ||
} | ||
length = data.byteLength; | ||
let length = data.byteLength; | ||
const offset = options.offset ? options.offset>>>0 : 0; | ||
if (data.buffer) { | ||
length = data.byteLength; | ||
length = data.byteLength - offset; | ||
if (data.byteLength !== data.buffer.byteLength) { // Node.js buffer from pool | ||
data = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength); | ||
data = data.buffer.slice(data.byteOffset + offset, data.byteOffset + data.byteLength); | ||
} else if (offset) { | ||
data = data.buffer.slice(offset); | ||
} else { | ||
@@ -29,2 +31,4 @@ data = data.buffer; | ||
this.length = length; | ||
this.byteLength = length; | ||
this.byteOffset = 0; | ||
this.offset = 0; | ||
@@ -31,0 +35,0 @@ this.littleEndian = true; |
{ | ||
"name": "iobuffer", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Read and write binary data on ArrayBuffers", | ||
@@ -11,4 +11,4 @@ "main": "./IOBuffer.js", | ||
"test": "mocha --require should --reporter mocha-better-spec-reporter --recursive", | ||
"test-cov": "babel-istanbul cover node_modules/.bin/_mocha -- --require should --reporter dot --recursive", | ||
"test-travis": "babel-istanbul cover node_modules/.bin/_mocha --report lcovonly -- --require should --reporter mocha-better-spec-reporter --recursive" | ||
"test-cov": "istanbul cover node_modules/.bin/_mocha -- --require should --reporter dot --recursive", | ||
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --require should --reporter mocha-better-spec-reporter --recursive" | ||
}, | ||
@@ -26,7 +26,7 @@ "repository": { | ||
"devDependencies": { | ||
"babel-istanbul": "^0.4.0", | ||
"mocha": "^2.3.3", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.0.2", | ||
"mocha-better-spec-reporter": "^3.0.0", | ||
"should": "^7.1.0" | ||
"should": "^11.1.0" | ||
} | ||
} |
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
10195
203