byte-data-stream
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,2 +0,3 @@ | ||
export declare class ByteStream { | ||
import { ByteStreamInterface } from './ByteStreamInterface.js'; | ||
export declare class ByteStream implements ByteStreamInterface { | ||
#private; | ||
@@ -7,3 +8,3 @@ i: number; | ||
private littleEndian; | ||
constructor(buf: ArrayBuffer | Uint8Array, littleEndian?: boolean); | ||
constructor(buf?: ArrayBuffer | Uint8Array, littleEndian?: boolean); | ||
get buffer(): ArrayBuffer; | ||
@@ -14,3 +15,3 @@ get length(): number; | ||
readUint8(): number; | ||
readBytes(length: any): Uint8Array; | ||
readBytes(length: number): Uint8Array; | ||
readInt16(oppositeEndian?: boolean): number; | ||
@@ -17,0 +18,0 @@ readUint16(oppositeEndian?: boolean): number; |
@@ -9,3 +9,3 @@ import varint from 'signed-varint'; | ||
littleEndian; | ||
constructor(buf, littleEndian = false) { | ||
constructor(buf = null, littleEndian = false) { | ||
this.#buf = buf ? this.#ensureArrayBuffer(buf) : new ArrayBuffer(0); | ||
@@ -12,0 +12,0 @@ this.i = 0; |
@@ -0,29 +1,28 @@ | ||
import { ByteStreamInterface } from './ByteStreamInterface.js'; | ||
export declare class WriteOnlyException extends Error { | ||
constructor(...args: any[]); | ||
} | ||
export declare class ByteStreamSimulator { | ||
export declare class ByteStreamSimulator implements ByteStreamInterface { | ||
#private; | ||
i: number; | ||
constructor(buf?: ArrayBuffer); | ||
constructor(buf: ArrayBuffer | Uint8Array); | ||
get buffer(): ArrayBuffer; | ||
get length(): number; | ||
get isDataAvailable(): boolean; | ||
readInt8(): void; | ||
readUint8(): void; | ||
readBytes(): void; | ||
readInt16(): void; | ||
readUint16(): void; | ||
readInt32(): void; | ||
readUint32(): void; | ||
readBigInt64(): void; | ||
readBigUint64(): void; | ||
readFloat32(): void; | ||
readFloat64(): void; | ||
readVarIntBytes(): void; | ||
readVarInt(): void; | ||
readVarUint(): void; | ||
expandBuffer(len: number): void; | ||
readInt8(): number; | ||
readUint8(): number; | ||
readBytes(): Uint8Array; | ||
readInt16(): number; | ||
readUint16(): number; | ||
readInt32(): number; | ||
readUint32(): number; | ||
readBigInt64(): bigint; | ||
readBigUint64(): bigint; | ||
readFloat32(): number; | ||
readFloat64(): number; | ||
readVarInt(): number; | ||
readVarUint(): number; | ||
writeInt8(): void; | ||
writeUint8(): void; | ||
writeBytes(bytes: any): void; | ||
writeBytes(bytes: number[] | Uint8Array): void; | ||
writeInt16(): void; | ||
@@ -37,4 +36,4 @@ writeUint16(): void; | ||
writeFloat64(): void; | ||
writeVarInt(val: any): void; | ||
writeVarUint(val: any): void; | ||
writeVarInt(val: number): void; | ||
writeVarUint(val: number): void; | ||
} |
@@ -58,5 +58,2 @@ import varint from 'signed-varint'; | ||
} | ||
readVarIntBytes() { | ||
throw new WriteOnlyException(null); | ||
} | ||
readVarInt() { | ||
@@ -68,3 +65,3 @@ throw new WriteOnlyException(null); | ||
} | ||
expandBuffer(len) { | ||
#expandBuffer(len) { | ||
if (this.#byteLength >= this.i + len) | ||
@@ -75,7 +72,7 @@ return; | ||
writeInt8() { | ||
this.expandBuffer(1); | ||
this.#expandBuffer(1); | ||
this.i++; | ||
} | ||
writeUint8() { | ||
this.expandBuffer(1); | ||
this.#expandBuffer(1); | ||
this.i++; | ||
@@ -90,31 +87,31 @@ } | ||
writeInt16() { | ||
this.expandBuffer(2); | ||
this.#expandBuffer(2); | ||
this.i += 2; | ||
} | ||
writeUint16() { | ||
this.expandBuffer(2); | ||
this.#expandBuffer(2); | ||
this.i += 2; | ||
} | ||
writeInt32() { | ||
this.expandBuffer(4); | ||
this.#expandBuffer(4); | ||
this.i += 4; | ||
} | ||
writeUint32() { | ||
this.expandBuffer(4); | ||
this.#expandBuffer(4); | ||
this.i += 4; | ||
} | ||
writeBigInt64() { | ||
this.expandBuffer(8); | ||
this.#expandBuffer(8); | ||
this.i += 8; | ||
} | ||
writeBigUint64() { | ||
this.expandBuffer(8); | ||
this.#expandBuffer(8); | ||
this.i += 8; | ||
} | ||
writeFloat32() { | ||
this.expandBuffer(4); | ||
this.#expandBuffer(4); | ||
this.i += 4; | ||
} | ||
writeFloat64() { | ||
this.expandBuffer(8); | ||
this.#expandBuffer(8); | ||
this.i += 8; | ||
@@ -131,3 +128,2 @@ } | ||
} | ||
; | ||
//# sourceMappingURL=ByteStreamSimulator.js.map |
{ | ||
"name": "byte-data-stream", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Readable & writable byte data stream", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import varint from 'signed-varint'; | ||
import varuint from 'varint'; | ||
import { ByteStreamInterface } from './ByteStreamInterface.js'; | ||
@@ -7,3 +8,3 @@ /** | ||
*/ | ||
export class ByteStream { | ||
export class ByteStream implements ByteStreamInterface { | ||
i: number; | ||
@@ -15,3 +16,3 @@ #buf: ArrayBuffer; | ||
constructor(buf: ArrayBuffer | Uint8Array, littleEndian: boolean = false) { | ||
constructor(buf: ArrayBuffer | Uint8Array = null, littleEndian: boolean = false) { | ||
this.#buf = buf ? this.#ensureArrayBuffer(buf) : new ArrayBuffer(0); | ||
@@ -57,3 +58,3 @@ this.i = 0; | ||
readBytes(length): Uint8Array { | ||
readBytes(length: number): Uint8Array { | ||
if (this.i + length > this.#buf.byteLength) { | ||
@@ -60,0 +61,0 @@ throw new RangeError('Offset is outside the bounds of the ArrayBuffer'); |
import varint from 'signed-varint'; | ||
import varuint from 'varint'; | ||
import { ByteStreamInterface } from './ByteStreamInterface.js'; | ||
@@ -14,7 +15,7 @@ export class WriteOnlyException extends Error { | ||
*/ | ||
export class ByteStreamSimulator { | ||
export class ByteStreamSimulator implements ByteStreamInterface { | ||
i: number; | ||
#byteLength: number; | ||
constructor(buf?: ArrayBuffer) { | ||
constructor(buf: ArrayBuffer | Uint8Array) { | ||
this.i = 0; | ||
@@ -36,60 +37,56 @@ this.#byteLength = 0; | ||
readInt8() { | ||
readInt8(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readUint8() { | ||
readUint8(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readBytes() { | ||
readBytes(): Uint8Array { | ||
throw new WriteOnlyException(null); | ||
} | ||
readInt16() { | ||
readInt16(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readUint16() { | ||
readUint16(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readInt32() { | ||
readInt32(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readUint32() { | ||
readUint32(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readBigInt64() { | ||
readBigInt64(): bigint { | ||
throw new WriteOnlyException(null); | ||
} | ||
readBigUint64() { | ||
readBigUint64(): bigint { | ||
throw new WriteOnlyException(null); | ||
} | ||
readFloat32() { | ||
readFloat32(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readFloat64() { | ||
readFloat64(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readVarIntBytes() { | ||
readVarInt(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readVarInt() { | ||
readVarUint(): number { | ||
throw new WriteOnlyException(null); | ||
} | ||
readVarUint() { | ||
throw new WriteOnlyException(null); | ||
} | ||
// ArrayBuffer를 확장한다. | ||
expandBuffer(len: number) { | ||
#expandBuffer(len: number) { | ||
if (this.#byteLength >= this.i + len) return; | ||
@@ -100,3 +97,3 @@ this.#byteLength += this.i + len - this.#byteLength; | ||
writeInt8() { | ||
this.expandBuffer(1); | ||
this.#expandBuffer(1); | ||
this.i++; | ||
@@ -106,7 +103,7 @@ } | ||
writeUint8() { | ||
this.expandBuffer(1); | ||
this.#expandBuffer(1); | ||
this.i++; | ||
} | ||
writeBytes(bytes) { | ||
writeBytes(bytes: number[] | Uint8Array) { | ||
let b = [...bytes]; | ||
@@ -119,3 +116,3 @@ for (let i = 0; i < b.length; i++) { | ||
writeInt16() { | ||
this.expandBuffer(2); | ||
this.#expandBuffer(2); | ||
this.i += 2; | ||
@@ -125,3 +122,3 @@ } | ||
writeUint16() { | ||
this.expandBuffer(2); | ||
this.#expandBuffer(2); | ||
this.i += 2; | ||
@@ -131,3 +128,3 @@ } | ||
writeInt32() { | ||
this.expandBuffer(4); | ||
this.#expandBuffer(4); | ||
this.i += 4; | ||
@@ -137,3 +134,3 @@ } | ||
writeUint32() { | ||
this.expandBuffer(4); | ||
this.#expandBuffer(4); | ||
this.i += 4; | ||
@@ -143,3 +140,3 @@ } | ||
writeBigInt64() { | ||
this.expandBuffer(8); | ||
this.#expandBuffer(8); | ||
this.i += 8; | ||
@@ -149,3 +146,3 @@ } | ||
writeBigUint64() { | ||
this.expandBuffer(8); | ||
this.#expandBuffer(8); | ||
this.i += 8; | ||
@@ -155,3 +152,3 @@ } | ||
writeFloat32() { | ||
this.expandBuffer(4); | ||
this.#expandBuffer(4); | ||
this.i += 4; | ||
@@ -161,7 +158,7 @@ } | ||
writeFloat64() { | ||
this.expandBuffer(8); | ||
this.#expandBuffer(8); | ||
this.i += 8; | ||
} | ||
writeVarInt(val) { | ||
writeVarInt(val: number) { | ||
let a = varint.encode(val); | ||
@@ -171,3 +168,3 @@ a.forEach(() => this.writeUint8()); | ||
writeVarUint(val) { | ||
writeVarUint(val: number) { | ||
let a = varuint.encode(val); | ||
@@ -174,0 +171,0 @@ a.forEach(() => this.writeUint8()); |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45329
21
865
0