byte-data-stream
Advanced tools
Comparing version 0.1.1-rokka0 to 0.1.2-rokka0
{ | ||
"name": "byte-data-stream", | ||
"version": "0.1.1-rokka0", | ||
"version": "0.1.2-rokka0", | ||
"description": "Readable & writable byte data stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,2 +12,3 @@ const var_int = require('signed-varint'); | ||
this.view = new DataView(this.buf); | ||
this.u8 = new Uint8Array(this.buf); | ||
} | ||
@@ -28,7 +29,10 @@ | ||
read_bytes(length){ | ||
let arr = []; | ||
/*let arr = new Uint8Array(length); | ||
for(let i = 0;i < length;i++){ | ||
arr.push(this.read_uint8()); | ||
arr[i] = this.read_uint8(); | ||
}*/ | ||
if(this.i+length > this.buf.byteLength){ | ||
throw new RangeError('Offset is outside the bounds of the ArrayBuffer'); | ||
} | ||
return Uint8Array.from(arr); | ||
return this.u8.subarray(this.i,this.i += length); | ||
} | ||
@@ -121,7 +125,7 @@ | ||
if(len <= 0) return; | ||
let u8a1 = new Uint8Array(this.buf.byteLength+len); | ||
let u8a2 = new Uint8Array(this.buf); | ||
u8a1.set(u8a2); | ||
this.buf = u8a1.buffer; | ||
let u8 = new Uint8Array(this.buf.byteLength+len); | ||
u8.set(new Uint8Array(this.buf)); | ||
this.buf = u8.buffer; | ||
this.view = new DataView(this.buf); | ||
this.u8 = u8; | ||
} | ||
@@ -140,5 +144,5 @@ | ||
write_bytes(bytes){ | ||
for(let n of bytes){ | ||
this.write_uint8(n); | ||
} | ||
this.expand_buffer(bytes.length); | ||
this.u8.set(bytes,this.i); | ||
this.i += bytes.length; | ||
} | ||
@@ -145,0 +149,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
13559
323