@bfchain/bnrtc2-buffer
Advanced tools
Comparing version 0.0.0 to 0.0.1-alpha.1
@@ -32,2 +32,7 @@ export declare class Bnrtc2Buffer implements Bnrtc2.Bnrtc2Buffer { | ||
pullStr(size: number): string; | ||
peek(size: number): Uint8Array; | ||
peekU8(): number; | ||
peekU16(): number; | ||
peekU32(): number; | ||
peekStr(size: number): string; | ||
data(): Uint8Array; | ||
@@ -34,0 +39,0 @@ clone(): Bnrtc2Buffer; |
@@ -159,9 +159,6 @@ "use strict"; | ||
pull(size) { | ||
const len = this._endOffset - this._dataOffset; | ||
if (size > this._endOffset - this._dataOffset) { | ||
throw new RangeError(`size(${size} > data length(${len}))`); | ||
} | ||
const u8a = this.peek(size); | ||
this._dataOffset += size; | ||
this._isPulled = true; | ||
return this._buf.subarray(this._dataOffset - size, this._dataOffset); | ||
return u8a; | ||
} | ||
@@ -184,2 +181,25 @@ pullU8() { | ||
} | ||
peek(size) { | ||
const len = this._endOffset - this._dataOffset; | ||
if (size > this._endOffset - this._dataOffset) { | ||
throw new RangeError(`size(${size} > data length(${len}))`); | ||
} | ||
return this._buf.subarray(this._dataOffset, this._dataOffset + size); | ||
} | ||
peekU8() { | ||
const u8a = this.peek(1); | ||
return u8a[0]; | ||
} | ||
peekU16() { | ||
const u8a = this.peek(2); | ||
return (u8a[0] << 8) | u8a[1]; | ||
} | ||
peekU32() { | ||
const u8a = this.peek(4); | ||
return ((u8a[0] << 24) | (u8a[1] << 16) | (u8a[2] << 8) | u8a[3]) >>> 0; | ||
} | ||
peekStr(size) { | ||
const u8a = this.peek(size); | ||
return util_encoding_utf8_1.decodeBinaryToUTF8(u8a); | ||
} | ||
data() { | ||
@@ -186,0 +206,0 @@ return this._buf.subarray(this._dataOffset, this._endOffset); |
@@ -32,2 +32,7 @@ export declare class Bnrtc2Buffer implements Bnrtc2.Bnrtc2Buffer { | ||
pullStr(size: number): string; | ||
peek(size: number): Uint8Array; | ||
peekU8(): number; | ||
peekU16(): number; | ||
peekU32(): number; | ||
peekStr(size: number): string; | ||
data(): Uint8Array; | ||
@@ -34,0 +39,0 @@ clone(): Bnrtc2Buffer; |
@@ -170,9 +170,6 @@ import { encodeUTF8ToBinary, decodeBinaryToUTF8 } from "@bfchain/util-encoding-utf8"; | ||
Bnrtc2Buffer.prototype.pull = function (size) { | ||
var len = this._endOffset - this._dataOffset; | ||
if (size > this._endOffset - this._dataOffset) { | ||
throw new RangeError("size(" + size + " > data length(" + len + "))"); | ||
} | ||
var u8a = this.peek(size); | ||
this._dataOffset += size; | ||
this._isPulled = true; | ||
return this._buf.subarray(this._dataOffset - size, this._dataOffset); | ||
return u8a; | ||
}; | ||
@@ -195,2 +192,25 @@ Bnrtc2Buffer.prototype.pullU8 = function () { | ||
}; | ||
Bnrtc2Buffer.prototype.peek = function (size) { | ||
var len = this._endOffset - this._dataOffset; | ||
if (size > this._endOffset - this._dataOffset) { | ||
throw new RangeError("size(" + size + " > data length(" + len + "))"); | ||
} | ||
return this._buf.subarray(this._dataOffset, this._dataOffset + size); | ||
}; | ||
Bnrtc2Buffer.prototype.peekU8 = function () { | ||
var u8a = this.peek(1); | ||
return u8a[0]; | ||
}; | ||
Bnrtc2Buffer.prototype.peekU16 = function () { | ||
var u8a = this.peek(2); | ||
return (u8a[0] << 8) | u8a[1]; | ||
}; | ||
Bnrtc2Buffer.prototype.peekU32 = function () { | ||
var u8a = this.peek(4); | ||
return ((u8a[0] << 24) | (u8a[1] << 16) | (u8a[2] << 8) | u8a[3]) >>> 0; | ||
}; | ||
Bnrtc2Buffer.prototype.peekStr = function (size) { | ||
var u8a = this.peek(size); | ||
return decodeBinaryToUTF8(u8a); | ||
}; | ||
Bnrtc2Buffer.prototype.data = function () { | ||
@@ -197,0 +217,0 @@ return this._buf.subarray(this._dataOffset, this._endOffset); |
@@ -32,2 +32,7 @@ export declare class Bnrtc2Buffer implements Bnrtc2.Bnrtc2Buffer { | ||
pullStr(size: number): string; | ||
peek(size: number): Uint8Array; | ||
peekU8(): number; | ||
peekU16(): number; | ||
peekU32(): number; | ||
peekStr(size: number): string; | ||
data(): Uint8Array; | ||
@@ -34,0 +39,0 @@ clone(): Bnrtc2Buffer; |
@@ -156,9 +156,6 @@ import { encodeUTF8ToBinary, decodeBinaryToUTF8 } from "@bfchain/util-encoding-utf8"; | ||
pull(size) { | ||
const len = this._endOffset - this._dataOffset; | ||
if (size > this._endOffset - this._dataOffset) { | ||
throw new RangeError(`size(${size} > data length(${len}))`); | ||
} | ||
const u8a = this.peek(size); | ||
this._dataOffset += size; | ||
this._isPulled = true; | ||
return this._buf.subarray(this._dataOffset - size, this._dataOffset); | ||
return u8a; | ||
} | ||
@@ -181,2 +178,25 @@ pullU8() { | ||
} | ||
peek(size) { | ||
const len = this._endOffset - this._dataOffset; | ||
if (size > this._endOffset - this._dataOffset) { | ||
throw new RangeError(`size(${size} > data length(${len}))`); | ||
} | ||
return this._buf.subarray(this._dataOffset, this._dataOffset + size); | ||
} | ||
peekU8() { | ||
const u8a = this.peek(1); | ||
return u8a[0]; | ||
} | ||
peekU16() { | ||
const u8a = this.peek(2); | ||
return (u8a[0] << 8) | u8a[1]; | ||
} | ||
peekU32() { | ||
const u8a = this.peek(4); | ||
return ((u8a[0] << 24) | (u8a[1] << 16) | (u8a[2] << 8) | u8a[3]) >>> 0; | ||
} | ||
peekStr(size) { | ||
const u8a = this.peek(size); | ||
return decodeBinaryToUTF8(u8a); | ||
} | ||
data() { | ||
@@ -183,0 +203,0 @@ return this._buf.subarray(this._dataOffset, this._endOffset); |
{ | ||
"name": "@bfchain/bnrtc2-buffer", | ||
"version": "0.0.0", | ||
"version": "0.0.1-alpha.1", | ||
"main": "cjs/index.js", | ||
@@ -9,5 +9,5 @@ "type": "cjs/index.d.ts", | ||
"dependencies": { | ||
"@bfchain/bnrtc2-buffer-typings": "0.0.0", | ||
"@bfchain/bnrtc2-buffer-typings": "^0.0.1-alpha.1", | ||
"@bfchain/util-encoding-utf8": "^0.0.1-alpha.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29393
803
+ Added@bfchain/bnrtc2-buffer-typings@0.0.1-alpha.21(transitive)
- Removed@bfchain/bnrtc2-buffer-typings@0.0.0(transitive)