buffer-stream-js
Easy to use Uint8Array stream for read and write.
Example
; //Create BufferStream;//Write some datawriteStream.writeUInt834;writeStream.writeFloatBE5234;writeStream.writePackedUtf8String"Hello world!";//Get result as Uint8Array; //Create BufferStream from Uint8Array;//Read dataconsole.logreadStream.readUint8;console.logreadStream.readFloatBE;console.logreadStream.readPackedUtf8String;
Documentation
//Create BufferStream from ArrayBuffer or Uint8Arraynew BufferStreambuffer: ArrayBuffer | ArrayBufferView; //Creae with allocated memoryBufferStream.allocsize: number: BufferStream; //Read data and move cursorbufferStream.readlength: number: Uint8ArraybufferStream.readInt8: numberbufferStream.readInt16LE: numberbufferStream.readInt16BE: numberbufferStream.readInt32LE: numberbufferStream.readInt32BE: numberbufferStream.readUInt8: numberbufferStream.readUInt16LE: numberbufferStream.readUInt16BE: numberbufferStream.readUInt32LE: numberbufferStream.readUInt32BE: numberbufferStream.readFloatLE: numberbufferStream.readFloatBE: numberbufferStream.readDoubleLE: numberbufferStream.readDoubleBE: number //Write data and move cursorbufferStream.writedata: ArrayBuffer | ArrayBufferView | number: numberbufferStream.writeInt8data: number: voidbufferStream.writeInt16LEdata: number: voidbufferStream.writeInt16BEdata: number: voidbufferStream.writeInt32LEdata: number: voidbufferStream.writeInt32BEdata: number: voidbufferStream.writeUInt8data: number: voidbufferStream.writeUInt16LEdata: number: voidbufferStream.writeUInt16BEdata: number: voidbufferStream.writeUInt32LEdata: number: voidbufferStream.writeUInt32BEdata: number: voidbufferStream.writeFloatLEdata: number: voidbufferStream.writeFloatBEdata: number: voidbufferStream.writeDoubleLEdata: number: voidbufferStream.writeDoubleBEdata: number: void //Read & write boolean and move cursor, false is 0, true is 1 (one-byte)bufferStream.readBoolean: booleanbufferStream.writeBooleanvalue: boolean: void //Read & write dynamic size intbufferStream.readInt: numberbufferStream.writeIntdata: number: number //Read & write dynamic size unsigned intbufferStream.readUInt: numberbufferStream.writeUIntdata: number: number //Read & write packed data, first packed data has dynamic uint which indicates data length, and then the databufferStream.readPacked: Uint8ArraybufferStream.writePackeddata: ArrayBuffer | ArrayBufferView | number: number //Read & write utf8 stringbufferStream.readUtf8Stringlength: number: stringbufferStream.writeUtf8Stringdata: string: number //Read & write packed utf8 string, first packed data has dynamic uint which indicates data length, and then the databufferStream.readPackedUtf8String: stringbufferStream.writePackedUtf8Stringdata: string: number //Get buffers //Gives you left part of streambufferStream.getLeftBuffer: Uint8Array//Gives you unread part of streambufferStream.getRightBuffer: Uint8Array//Gives you unread part of stream as utf8 stringbufferStream.getRightBufferAsUtf8String: string //Utils methods //Move cursorbufferStream.moveoffset: number: void//Check if there is given number of bytes to readbufferStream.canReadbytes: number: boolean//The same as canRead but throws expection if notbufferStream.checkToReadbytes: number: void//Returns not yet read number of bytesbufferStream.toRead: number //Static methodsstatic readInt8data: ArrayBuffer | ArrayBufferView: number;static readInt16LEdata: ArrayBuffer | ArrayBufferView: number;static readInt16BEdata: ArrayBuffer | ArrayBufferView: number;static readInt32LEdata: ArrayBuffer | ArrayBufferView: number;static readInt32BEdata: ArrayBuffer | ArrayBufferView: number;static readUInt8data: ArrayBuffer | ArrayBufferView: number;static readUInt16LEdata: ArrayBuffer | ArrayBufferView: number;static readUInt16BEdata: ArrayBuffer | ArrayBufferView: number;static readUInt32LEdata: ArrayBuffer | ArrayBufferView: number;static readUInt32BEdata: ArrayBuffer | ArrayBufferView: number;static readFloatLEdata: ArrayBuffer | ArrayBufferView: number;static readFloatBEdata: ArrayBuffer | ArrayBufferView: number;static readDoubleLEdata: ArrayBuffer | ArrayBufferView: number;static readDoubleBEdata: ArrayBuffer | ArrayBufferView: number;static writeInt8data: number: Uint8Array;static writeInt16LEdata: number: Uint8Array;static writeInt16BEdata: number: Uint8Array;static writeInt32LEdata: number: Uint8Array;static writeInt32BEdata: number: Uint8Array;static writeUInt8data: number: Uint8Array;static writeUInt16LEdata: number: Uint8Array;static writeUInt16BEdata: number: Uint8Array;static writeUInt32LEdata: number: Uint8Array;static writeUInt32BEdata: number: Uint8Array;static writeFloatLEdata: number: Uint8Array;static writeFloatBEdata: number: Uint8Array;static writeDoubleLEdata: number: Uint8Array;static writeDoubleBEdata: number: Uint8Array;static readBooleandata: ArrayBuffer | ArrayBufferView: boolean;static writeBooleanvalue: boolean: Uint8Array;static readIntdata: ArrayBuffer | ArrayBufferView: number;static writeIntdata: number: Uint8Array;static readUIntdata: ArrayBuffer | ArrayBufferView: number;static writeUIntdata: number: Uint8Array;static readPackeddata: ArrayBuffer | ArrayBufferView: Uint8Array;static writePackeddata: ArrayBuffer | ArrayBufferView | number: Uint8Array;static readUtf8Stringdata: ArrayBuffer | ArrayBufferView, length?: number: string;static writeUtf8Stringdata: string: Uint8Array;static readPackedUtf8Stringdata: ArrayBuffer | ArrayBufferView: string;static writePackedUtf8Stringdata: string: Uint8Array;
License
The MIT License (MIT)