Comparing version 4.0.0 to 4.0.1
@@ -0,1 +1,5 @@ | ||
## [4.0.1](https://github.com/image-js/iobuffer/compare/v4.0.0...v4.0.1) (2019-03-27) | ||
<a name="4.0.0"></a> | ||
@@ -2,0 +6,0 @@ # [4.0.0](https://github.com/image-js/iobuffer/compare/v3.2.0...v4.0.0) (2018-08-22) |
/// <reference types="node" /> | ||
declare type InputData = number | ArrayBufferLike | ArrayBufferView | IOBuffer | Buffer; | ||
interface IOBufferOptions { | ||
/** | ||
* Ignore the first n bytes of the ArrayBuffer. | ||
*/ | ||
offset?: number; | ||
} | ||
/** | ||
* IOBuffer | ||
* @constructor | ||
* @param {number|ArrayBufferLike|ArrayBufferView|IOBuffer|Buffer} [data] - The data to construct the IOBuffer with. | ||
* | ||
* If data is a number, it will be the new buffer's length<br> | ||
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br> | ||
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance, | ||
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer. | ||
* @param {object} [options] | ||
* @param {number} [options.offset=0] - Ignore the first n bytes of the ArrayBuffer | ||
* @property {ArrayBuffer} buffer - Reference to the internal ArrayBuffer object | ||
* @property {number} length - Byte length of the internal ArrayBuffer | ||
* @property {number} offset - The current offset of the buffer's pointer | ||
* @property {number} byteLength - Byte length of the internal ArrayBuffer | ||
* @property {number} byteOffset - Byte offset of the internal ArrayBuffer | ||
*/ | ||
export declare class IOBuffer { | ||
/** | ||
* Reference to the internal ArrayBuffer object. | ||
*/ | ||
buffer: ArrayBufferLike; | ||
/** | ||
* Byte length of the internal ArrayBuffer. | ||
*/ | ||
byteLength: number; | ||
/** | ||
* Byte offset of the internal ArrayBuffer. | ||
*/ | ||
byteOffset: number; | ||
lastWrittenByte: number; | ||
/** | ||
* Byte length of the internal ArrayBuffer. | ||
*/ | ||
length: number; | ||
littleEndian: boolean; | ||
/** | ||
* The current offset of the buffer's pointer. | ||
*/ | ||
offset: number; | ||
private lastWrittenByte; | ||
private littleEndian; | ||
private _data; | ||
private _mark; | ||
private _marks; | ||
/** | ||
* @param data - The data to construct the IOBuffer with. | ||
* If data is a number, it will be the new buffer's length<br> | ||
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br> | ||
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance, | ||
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer. | ||
* @param options | ||
*/ | ||
constructor(data?: InputData, options?: IOBufferOptions); | ||
/** | ||
* Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset | ||
* @param {number} [byteLength=1] The needed memory in bytes | ||
* @return {boolean} Returns true if there is sufficient space and false otherwise | ||
* Checks if the memory allocated to the buffer is sufficient to store more | ||
* bytes after the offset. | ||
* @param byteLength - The needed memory in bytes. | ||
* @returns `true` if there is sufficient space and `false` otherwise. | ||
*/ | ||
available(byteLength?: number): boolean; | ||
/** | ||
* Check if little-endian mode is used for reading and writing multi-byte values | ||
* @return {boolean} Returns true if little-endian mode is used, false otherwise | ||
* Check if little-endian mode is used for reading and writing multi-byte | ||
* values. | ||
* @returns `true` if little-endian mode is used, `false` otherwise. | ||
*/ | ||
isLittleEndian(): boolean; | ||
/** | ||
* Set little-endian mode for reading and writing multi-byte values | ||
* @return {IOBuffer} | ||
* Set little-endian mode for reading and writing multi-byte values. | ||
*/ | ||
setLittleEndian(): IOBuffer; | ||
setLittleEndian(): this; | ||
/** | ||
* Check if big-endian mode is used for reading and writing multi-byte values | ||
* @return {boolean} Returns true if big-endian mode is used, false otherwise | ||
* Check if big-endian mode is used for reading and writing multi-byte values. | ||
* @returns `true` if big-endian mode is used, `false` otherwise. | ||
*/ | ||
isBigEndian(): boolean; | ||
/** | ||
* Switches to big-endian mode for reading and writing multi-byte values | ||
* @return {IOBuffer} | ||
* Switches to big-endian mode for reading and writing multi-byte values. | ||
*/ | ||
setBigEndian(): IOBuffer; | ||
setBigEndian(): this; | ||
/** | ||
* Move the pointer n bytes forward | ||
* @param {number} n | ||
* @return {IOBuffer} | ||
* Move the pointer n bytes forward. | ||
* @param n - Number of bytes to skip. | ||
*/ | ||
skip(n?: number): IOBuffer; | ||
skip(n?: number): this; | ||
/** | ||
* Move the pointer to the given offset | ||
* @param {number} offset | ||
* @return {IOBuffer} | ||
* Move the pointer to the given offset. | ||
* @param offset | ||
*/ | ||
seek(offset: number): IOBuffer; | ||
seek(offset: number): this; | ||
/** | ||
* Store the current pointer offset. | ||
* @see {@link IOBuffer#reset} | ||
* @return {IOBuffer} | ||
*/ | ||
mark(): IOBuffer; | ||
mark(): this; | ||
/** | ||
* Move the pointer back to the last pointer offset set by mark | ||
* Move the pointer back to the last pointer offset set by mark. | ||
* @see {@link IOBuffer#mark} | ||
* @return {IOBuffer} | ||
*/ | ||
reset(): IOBuffer; | ||
reset(): this; | ||
/** | ||
* Push the current pointer offset to the mark stack | ||
* Push the current pointer offset to the mark stack. | ||
* @see {@link IOBuffer#popMark} | ||
* @return {IOBuffer} | ||
*/ | ||
pushMark(): IOBuffer; | ||
pushMark(): this; | ||
/** | ||
* Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value | ||
* Pop the last pointer offset from the mark stack, and set the current | ||
* pointer offset to the popped value. | ||
* @see {@link IOBuffer#pushMark} | ||
* @return {IOBuffer} | ||
*/ | ||
popMark(): IOBuffer; | ||
popMark(): this; | ||
/** | ||
* Move the pointer offset back to 0 | ||
* @return {IOBuffer} | ||
* Move the pointer offset back to 0. | ||
*/ | ||
rewind(): IOBuffer; | ||
rewind(): this; | ||
/** | ||
* Make sure the buffer has sufficient memory to write a given byteLength at the current pointer offset | ||
* If the buffer's memory is insufficient, this method will create a new buffer (a copy) with a length | ||
* that is twice (byteLength + current offset) | ||
* @param {number} [byteLength = 1] | ||
* @return {IOBuffer} | ||
* Make sure the buffer has sufficient memory to write a given byteLength at | ||
* the current pointer offset. | ||
* If the buffer's memory is insufficient, this method will create a new | ||
* buffer (a copy) with a length that is twice (byteLength + current offset). | ||
* @param byteLength | ||
*/ | ||
ensureAvailable(byteLength?: number): IOBuffer; | ||
ensureAvailable(byteLength?: number): this; | ||
/** | ||
* Read a byte and return false if the byte's value is 0, or true otherwise | ||
* Moves pointer forward | ||
* @return {boolean} | ||
* Read a byte and return false if the byte's value is 0, or true otherwise. | ||
* Moves pointer forward by one byte. | ||
*/ | ||
readBoolean(): boolean; | ||
/** | ||
* Read a signed 8-bit integer and move pointer forward | ||
* @return {number} | ||
* Read a signed 8-bit integer and move pointer forward by 1 byte. | ||
*/ | ||
readInt8(): number; | ||
/** | ||
* Read an unsigned 8-bit integer and move pointer forward | ||
* @return {number} | ||
* Read an unsigned 8-bit integer and move pointer forward by 1 byte. | ||
*/ | ||
readUint8(): number; | ||
/** | ||
* Alias for {@link IOBuffer#readUint8} | ||
* @return {number} | ||
* Alias for {@link IOBuffer#readUint8}. | ||
*/ | ||
readByte(): number; | ||
/** | ||
* Read n bytes and move pointer forward. | ||
* @param {number} n | ||
* @return {Uint8Array} | ||
* Read `n` bytes and move pointer forward by `n` bytes. | ||
*/ | ||
readBytes(n?: number): Uint8Array; | ||
/** | ||
* Read a 16-bit signed integer and move pointer forward | ||
* @return {number} | ||
* Read a 16-bit signed integer and move pointer forward by 2 bytes. | ||
*/ | ||
readInt16(): number; | ||
/** | ||
* Read a 16-bit unsigned integer and move pointer forward | ||
* @return {number} | ||
* Read a 16-bit unsigned integer and move pointer forward by 2 bytes. | ||
*/ | ||
readUint16(): number; | ||
/** | ||
* Read a 32-bit signed integer and move pointer forward | ||
* @return {number} | ||
* Read a 32-bit signed integer and move pointer forward by 4 bytes. | ||
*/ | ||
readInt32(): number; | ||
/** | ||
* Read a 32-bit unsigned integer and move pointer forward | ||
* @return {number} | ||
* Read a 32-bit unsigned integer and move pointer forward by 4 bytes. | ||
*/ | ||
readUint32(): number; | ||
/** | ||
* Read a 32-bit floating number and move pointer forward | ||
* @return {number} | ||
* Read a 32-bit floating number and move pointer forward by 4 bytes. | ||
*/ | ||
readFloat32(): number; | ||
/** | ||
* Read a 64-bit floating number and move pointer forward | ||
* @return {number} | ||
* Read a 64-bit floating number and move pointer forward by 8 bytes. | ||
*/ | ||
readFloat64(): number; | ||
/** | ||
* Read 1-byte ascii character and move pointer forward | ||
* @return {string} | ||
* Read a 1-byte ASCII character and move pointer forward by 1 byte. | ||
*/ | ||
readChar(): string; | ||
/** | ||
* Read n 1-byte ascii characters and move pointer forward | ||
* @param {number} n | ||
* @return {string} | ||
* Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes. | ||
*/ | ||
readChars(n?: number): string; | ||
/** | ||
* Read the next n bytes, return a UTF-8 decoded string and move pointer forward | ||
* @param {number} n | ||
* @return {string} | ||
* Read the next `n` bytes, return a UTF-8 decoded string and move pointer | ||
* forward by `n` bytes. | ||
*/ | ||
readUtf8(n?: number): string; | ||
/** | ||
* Write 0xff if the passed value is truthy, 0x00 otherwise | ||
* @param {any} value | ||
* @return {IOBuffer} | ||
* Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer | ||
* forward by 1 byte. | ||
*/ | ||
writeBoolean(value: any): IOBuffer; | ||
writeBoolean(value: unknown): this; | ||
/** | ||
* Write value as an 8-bit signed integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as an 8-bit signed integer and move pointer forward by 1 byte. | ||
*/ | ||
writeInt8(value: number): IOBuffer; | ||
writeInt8(value: number): this; | ||
/** | ||
* Write value as a 8-bit unsigned integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as an 8-bit unsigned integer and move pointer forward by 1 | ||
* byte. | ||
*/ | ||
writeUint8(value: number): IOBuffer; | ||
writeUint8(value: number): this; | ||
/** | ||
* An alias for {@link IOBuffer#writeUint8} | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* An alias for {@link IOBuffer#writeUint8}. | ||
*/ | ||
writeByte(value: number): IOBuffer; | ||
writeByte(value: number): this; | ||
/** | ||
* Write bytes | ||
* @param {ArrayLike<number>} bytes | ||
* @return {IOBuffer} | ||
* Write all elements of `bytes` as uint8 values and move pointer forward by | ||
* `bytes.length` bytes. | ||
*/ | ||
writeBytes(bytes: ArrayLike<number>): IOBuffer; | ||
writeBytes(bytes: ArrayLike<number>): this; | ||
/** | ||
* Write value as an 16-bit signed integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 16-bit signed integer and move pointer forward by 2 | ||
* bytes. | ||
*/ | ||
writeInt16(value: number): IOBuffer; | ||
writeInt16(value: number): this; | ||
/** | ||
* Write value as a 16-bit unsigned integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 16-bit unsigned integer and move pointer forward by 2 | ||
* bytes. | ||
*/ | ||
writeUint16(value: number): IOBuffer; | ||
writeUint16(value: number): this; | ||
/** | ||
* Write a 32-bit signed integer at the current pointer offset | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 32-bit signed integer and move pointer forward by 4 | ||
* bytes. | ||
*/ | ||
writeInt32(value: number): IOBuffer; | ||
writeInt32(value: number): this; | ||
/** | ||
* Write a 32-bit unsigned integer at the current pointer offset | ||
* @param {number} value - The value to set | ||
* @return {IOBuffer} | ||
* Write `value` as a 32-bit unsigned integer and move pointer forward by 4 | ||
* bytes. | ||
*/ | ||
writeUint32(value: number): IOBuffer; | ||
writeUint32(value: number): this; | ||
/** | ||
* Write a 32-bit floating number at the current pointer offset | ||
* @param {number} value - The value to set | ||
* @return {IOBuffer} | ||
* Write `value` as a 32-bit floating number and move pointer forward by 4 | ||
* bytes. | ||
*/ | ||
writeFloat32(value: number): IOBuffer; | ||
writeFloat32(value: number): this; | ||
/** | ||
* Write a 64-bit floating number at the current pointer offset | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 64-bit floating number and move pointer forward by 8 | ||
* bytes. | ||
*/ | ||
writeFloat64(value: number): IOBuffer; | ||
writeFloat64(value: number): this; | ||
/** | ||
* Write the charCode of the passed string's first character to the current pointer offset | ||
* @param {string} str - The character to set | ||
* @return {IOBuffer} | ||
* Write the charCode of `str`'s first character as an 8-bit unsigned integer | ||
* and move pointer forward by 1 byte. | ||
*/ | ||
writeChar(str: string): IOBuffer; | ||
writeChar(str: string): this; | ||
/** | ||
* Write the charCodes of the passed string's characters to the current pointer offset | ||
* @param {string} str | ||
* @return {IOBuffer} | ||
* Write the charCodes of all `str`'s characters as 8-bit unsigned integers | ||
* and move pointer forward by `str.length` bytes. | ||
*/ | ||
writeChars(str: string): IOBuffer; | ||
writeChars(str: string): this; | ||
/** | ||
* UTF-8 encode and write the passed string to the current pointer offset | ||
* @param {string} str | ||
* @return {IOBuffer} | ||
* UTF-8 encode and write `str` to the current pointer offset and move pointer | ||
* forward according to the encoded length. | ||
*/ | ||
writeUtf8(str: string): IOBuffer; | ||
writeUtf8(str: string): this; | ||
/** | ||
@@ -272,3 +243,2 @@ * Export a Uint8Array view of the internal buffer. | ||
* is calculated to stop at the last written byte or the original length. | ||
* @return {Uint8Array} | ||
*/ | ||
@@ -275,0 +245,0 @@ toArray(): Uint8Array; |
@@ -5,21 +5,11 @@ "use strict"; | ||
const defaultByteLength = 1024 * 8; | ||
const charArray = []; | ||
/** | ||
* IOBuffer | ||
* @constructor | ||
* @param {number|ArrayBufferLike|ArrayBufferView|IOBuffer|Buffer} [data] - The data to construct the IOBuffer with. | ||
* | ||
* If data is a number, it will be the new buffer's length<br> | ||
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br> | ||
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance, | ||
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer. | ||
* @param {object} [options] | ||
* @param {number} [options.offset=0] - Ignore the first n bytes of the ArrayBuffer | ||
* @property {ArrayBuffer} buffer - Reference to the internal ArrayBuffer object | ||
* @property {number} length - Byte length of the internal ArrayBuffer | ||
* @property {number} offset - The current offset of the buffer's pointer | ||
* @property {number} byteLength - Byte length of the internal ArrayBuffer | ||
* @property {number} byteOffset - Byte offset of the internal ArrayBuffer | ||
*/ | ||
class IOBuffer { | ||
/** | ||
* @param data - The data to construct the IOBuffer with. | ||
* If data is a number, it will be the new buffer's length<br> | ||
* If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br> | ||
* If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance, | ||
* or a Node.js Buffer, a view will be created over the underlying ArrayBuffer. | ||
* @param options | ||
*/ | ||
constructor(data = defaultByteLength, options = {}) { | ||
@@ -60,5 +50,6 @@ let dataIsGiven = false; | ||
/** | ||
* Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset | ||
* @param {number} [byteLength=1] The needed memory in bytes | ||
* @return {boolean} Returns true if there is sufficient space and false otherwise | ||
* Checks if the memory allocated to the buffer is sufficient to store more | ||
* bytes after the offset. | ||
* @param byteLength - The needed memory in bytes. | ||
* @returns `true` if there is sufficient space and `false` otherwise. | ||
*/ | ||
@@ -69,4 +60,5 @@ available(byteLength = 1) { | ||
/** | ||
* Check if little-endian mode is used for reading and writing multi-byte values | ||
* @return {boolean} Returns true if little-endian mode is used, false otherwise | ||
* Check if little-endian mode is used for reading and writing multi-byte | ||
* values. | ||
* @returns `true` if little-endian mode is used, `false` otherwise. | ||
*/ | ||
@@ -77,4 +69,3 @@ isLittleEndian() { | ||
/** | ||
* Set little-endian mode for reading and writing multi-byte values | ||
* @return {IOBuffer} | ||
* Set little-endian mode for reading and writing multi-byte values. | ||
*/ | ||
@@ -86,4 +77,4 @@ setLittleEndian() { | ||
/** | ||
* Check if big-endian mode is used for reading and writing multi-byte values | ||
* @return {boolean} Returns true if big-endian mode is used, false otherwise | ||
* Check if big-endian mode is used for reading and writing multi-byte values. | ||
* @returns `true` if big-endian mode is used, `false` otherwise. | ||
*/ | ||
@@ -94,4 +85,3 @@ isBigEndian() { | ||
/** | ||
* Switches to big-endian mode for reading and writing multi-byte values | ||
* @return {IOBuffer} | ||
* Switches to big-endian mode for reading and writing multi-byte values. | ||
*/ | ||
@@ -103,5 +93,4 @@ setBigEndian() { | ||
/** | ||
* Move the pointer n bytes forward | ||
* @param {number} n | ||
* @return {IOBuffer} | ||
* Move the pointer n bytes forward. | ||
* @param n - Number of bytes to skip. | ||
*/ | ||
@@ -113,5 +102,4 @@ skip(n = 1) { | ||
/** | ||
* Move the pointer to the given offset | ||
* @param {number} offset | ||
* @return {IOBuffer} | ||
* Move the pointer to the given offset. | ||
* @param offset | ||
*/ | ||
@@ -125,3 +113,2 @@ seek(offset) { | ||
* @see {@link IOBuffer#reset} | ||
* @return {IOBuffer} | ||
*/ | ||
@@ -133,5 +120,4 @@ mark() { | ||
/** | ||
* Move the pointer back to the last pointer offset set by mark | ||
* Move the pointer back to the last pointer offset set by mark. | ||
* @see {@link IOBuffer#mark} | ||
* @return {IOBuffer} | ||
*/ | ||
@@ -143,5 +129,4 @@ reset() { | ||
/** | ||
* Push the current pointer offset to the mark stack | ||
* Push the current pointer offset to the mark stack. | ||
* @see {@link IOBuffer#popMark} | ||
* @return {IOBuffer} | ||
*/ | ||
@@ -153,5 +138,5 @@ pushMark() { | ||
/** | ||
* Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value | ||
* Pop the last pointer offset from the mark stack, and set the current | ||
* pointer offset to the popped value. | ||
* @see {@link IOBuffer#pushMark} | ||
* @return {IOBuffer} | ||
*/ | ||
@@ -167,4 +152,3 @@ popMark() { | ||
/** | ||
* Move the pointer offset back to 0 | ||
* @return {IOBuffer} | ||
* Move the pointer offset back to 0. | ||
*/ | ||
@@ -176,7 +160,7 @@ rewind() { | ||
/** | ||
* Make sure the buffer has sufficient memory to write a given byteLength at the current pointer offset | ||
* If the buffer's memory is insufficient, this method will create a new buffer (a copy) with a length | ||
* that is twice (byteLength + current offset) | ||
* @param {number} [byteLength = 1] | ||
* @return {IOBuffer} | ||
* Make sure the buffer has sufficient memory to write a given byteLength at | ||
* the current pointer offset. | ||
* If the buffer's memory is insufficient, this method will create a new | ||
* buffer (a copy) with a length that is twice (byteLength + current offset). | ||
* @param byteLength | ||
*/ | ||
@@ -196,5 +180,4 @@ ensureAvailable(byteLength = 1) { | ||
/** | ||
* Read a byte and return false if the byte's value is 0, or true otherwise | ||
* Moves pointer forward | ||
* @return {boolean} | ||
* Read a byte and return false if the byte's value is 0, or true otherwise. | ||
* Moves pointer forward by one byte. | ||
*/ | ||
@@ -205,4 +188,3 @@ readBoolean() { | ||
/** | ||
* Read a signed 8-bit integer and move pointer forward | ||
* @return {number} | ||
* Read a signed 8-bit integer and move pointer forward by 1 byte. | ||
*/ | ||
@@ -213,4 +195,3 @@ readInt8() { | ||
/** | ||
* Read an unsigned 8-bit integer and move pointer forward | ||
* @return {number} | ||
* Read an unsigned 8-bit integer and move pointer forward by 1 byte. | ||
*/ | ||
@@ -221,4 +202,3 @@ readUint8() { | ||
/** | ||
* Alias for {@link IOBuffer#readUint8} | ||
* @return {number} | ||
* Alias for {@link IOBuffer#readUint8}. | ||
*/ | ||
@@ -229,5 +209,3 @@ readByte() { | ||
/** | ||
* Read n bytes and move pointer forward. | ||
* @param {number} n | ||
* @return {Uint8Array} | ||
* Read `n` bytes and move pointer forward by `n` bytes. | ||
*/ | ||
@@ -242,4 +220,3 @@ readBytes(n = 1) { | ||
/** | ||
* Read a 16-bit signed integer and move pointer forward | ||
* @return {number} | ||
* Read a 16-bit signed integer and move pointer forward by 2 bytes. | ||
*/ | ||
@@ -252,4 +229,3 @@ readInt16() { | ||
/** | ||
* Read a 16-bit unsigned integer and move pointer forward | ||
* @return {number} | ||
* Read a 16-bit unsigned integer and move pointer forward by 2 bytes. | ||
*/ | ||
@@ -262,4 +238,3 @@ readUint16() { | ||
/** | ||
* Read a 32-bit signed integer and move pointer forward | ||
* @return {number} | ||
* Read a 32-bit signed integer and move pointer forward by 4 bytes. | ||
*/ | ||
@@ -272,4 +247,3 @@ readInt32() { | ||
/** | ||
* Read a 32-bit unsigned integer and move pointer forward | ||
* @return {number} | ||
* Read a 32-bit unsigned integer and move pointer forward by 4 bytes. | ||
*/ | ||
@@ -282,4 +256,3 @@ readUint32() { | ||
/** | ||
* Read a 32-bit floating number and move pointer forward | ||
* @return {number} | ||
* Read a 32-bit floating number and move pointer forward by 4 bytes. | ||
*/ | ||
@@ -292,4 +265,3 @@ readFloat32() { | ||
/** | ||
* Read a 64-bit floating number and move pointer forward | ||
* @return {number} | ||
* Read a 64-bit floating number and move pointer forward by 8 bytes. | ||
*/ | ||
@@ -302,4 +274,3 @@ readFloat64() { | ||
/** | ||
* Read 1-byte ascii character and move pointer forward | ||
* @return {string} | ||
* Read a 1-byte ASCII character and move pointer forward by 1 byte. | ||
*/ | ||
@@ -310,17 +281,14 @@ readChar() { | ||
/** | ||
* Read n 1-byte ascii characters and move pointer forward | ||
* @param {number} n | ||
* @return {string} | ||
* Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes. | ||
*/ | ||
readChars(n = 1) { | ||
charArray.length = n; | ||
let result = ''; | ||
for (let i = 0; i < n; i++) { | ||
charArray[i] = this.readChar(); | ||
result += this.readChar(); | ||
} | ||
return charArray.join(''); | ||
return result; | ||
} | ||
/** | ||
* Read the next n bytes, return a UTF-8 decoded string and move pointer forward | ||
* @param {number} n | ||
* @return {string} | ||
* Read the next `n` bytes, return a UTF-8 decoded string and move pointer | ||
* forward by `n` bytes. | ||
*/ | ||
@@ -332,5 +300,4 @@ readUtf8(n = 1) { | ||
/** | ||
* Write 0xff if the passed value is truthy, 0x00 otherwise | ||
* @param {any} value | ||
* @return {IOBuffer} | ||
* Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer | ||
* forward by 1 byte. | ||
*/ | ||
@@ -342,5 +309,3 @@ writeBoolean(value) { | ||
/** | ||
* Write value as an 8-bit signed integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as an 8-bit signed integer and move pointer forward by 1 byte. | ||
*/ | ||
@@ -354,5 +319,4 @@ writeInt8(value) { | ||
/** | ||
* Write value as a 8-bit unsigned integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as an 8-bit unsigned integer and move pointer forward by 1 | ||
* byte. | ||
*/ | ||
@@ -366,5 +330,3 @@ writeUint8(value) { | ||
/** | ||
* An alias for {@link IOBuffer#writeUint8} | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* An alias for {@link IOBuffer#writeUint8}. | ||
*/ | ||
@@ -375,9 +337,7 @@ writeByte(value) { | ||
/** | ||
* Write bytes | ||
* @param {ArrayLike<number>} bytes | ||
* @return {IOBuffer} | ||
* Write all elements of `bytes` as uint8 values and move pointer forward by | ||
* `bytes.length` bytes. | ||
*/ | ||
writeBytes(bytes) { | ||
this.ensureAvailable(bytes.length); | ||
// tslint:disable-next-line prefer-for-of | ||
for (let i = 0; i < bytes.length; i++) { | ||
@@ -390,5 +350,4 @@ this._data.setUint8(this.offset++, bytes[i]); | ||
/** | ||
* Write value as an 16-bit signed integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 16-bit signed integer and move pointer forward by 2 | ||
* bytes. | ||
*/ | ||
@@ -403,5 +362,4 @@ writeInt16(value) { | ||
/** | ||
* Write value as a 16-bit unsigned integer | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 16-bit unsigned integer and move pointer forward by 2 | ||
* bytes. | ||
*/ | ||
@@ -416,5 +374,4 @@ writeUint16(value) { | ||
/** | ||
* Write a 32-bit signed integer at the current pointer offset | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 32-bit signed integer and move pointer forward by 4 | ||
* bytes. | ||
*/ | ||
@@ -429,5 +386,4 @@ writeInt32(value) { | ||
/** | ||
* Write a 32-bit unsigned integer at the current pointer offset | ||
* @param {number} value - The value to set | ||
* @return {IOBuffer} | ||
* Write `value` as a 32-bit unsigned integer and move pointer forward by 4 | ||
* bytes. | ||
*/ | ||
@@ -442,5 +398,4 @@ writeUint32(value) { | ||
/** | ||
* Write a 32-bit floating number at the current pointer offset | ||
* @param {number} value - The value to set | ||
* @return {IOBuffer} | ||
* Write `value` as a 32-bit floating number and move pointer forward by 4 | ||
* bytes. | ||
*/ | ||
@@ -455,5 +410,4 @@ writeFloat32(value) { | ||
/** | ||
* Write a 64-bit floating number at the current pointer offset | ||
* @param {number} value | ||
* @return {IOBuffer} | ||
* Write `value` as a 64-bit floating number and move pointer forward by 8 | ||
* bytes. | ||
*/ | ||
@@ -468,5 +422,4 @@ writeFloat64(value) { | ||
/** | ||
* Write the charCode of the passed string's first character to the current pointer offset | ||
* @param {string} str - The character to set | ||
* @return {IOBuffer} | ||
* Write the charCode of `str`'s first character as an 8-bit unsigned integer | ||
* and move pointer forward by 1 byte. | ||
*/ | ||
@@ -477,5 +430,4 @@ writeChar(str) { | ||
/** | ||
* Write the charCodes of the passed string's characters to the current pointer offset | ||
* @param {string} str | ||
* @return {IOBuffer} | ||
* Write the charCodes of all `str`'s characters as 8-bit unsigned integers | ||
* and move pointer forward by `str.length` bytes. | ||
*/ | ||
@@ -489,5 +441,4 @@ writeChars(str) { | ||
/** | ||
* UTF-8 encode and write the passed string to the current pointer offset | ||
* @param {string} str | ||
* @return {IOBuffer} | ||
* UTF-8 encode and write `str` to the current pointer offset and move pointer | ||
* forward according to the encoded length. | ||
*/ | ||
@@ -502,3 +453,2 @@ writeUtf8(str) { | ||
* is calculated to stop at the last written byte or the original length. | ||
* @return {Uint8Array} | ||
*/ | ||
@@ -519,1 +469,2 @@ toArray() { | ||
exports.IOBuffer = IOBuffer; | ||
//# sourceMappingURL=IOBuffer.js.map |
{ | ||
"name": "iobuffer", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Read and write binary data on ArrayBuffers", | ||
"main": "./lib/IOBuffer.js", | ||
"module": "./lib-es6/IOBuffer.js", | ||
"module": "./lib-esm/IOBuffer.js", | ||
"types": "./lib/IOBuffer.d.ts", | ||
"files": [ | ||
"lib", | ||
"lib-es6" | ||
"lib-esm" | ||
], | ||
"scripts": { | ||
"clean": "rimraf lib lib-es6", | ||
"test": "npm run test-only && npm run tslint", | ||
"clean": "rimraf lib lib-esm", | ||
"eslint": "eslint src --ext ts", | ||
"eslint-fix": "npm run eslint -- --fix", | ||
"prepublishOnly": "npm run tsc", | ||
"test": "npm run test-coverage && npm run eslint", | ||
"test-coverage": "npm run test-only -- --coverage", | ||
"test-only": "jest", | ||
"test-travis": "npm run test-coverage && npm run tslint", | ||
"tsc": "npm run clean && npm run tsc-es5 && npm run tsc-es6", | ||
"tsc-es5": "tsc", | ||
"tsc-es6": "tsc --project tsconfig.es6.json", | ||
"tslint": "tslint --project tsconfig.base.json", | ||
"tslint-fix": "npm run tslint -- --fix" | ||
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm", | ||
"tsc-cjs": "tsc", | ||
"tsc-esm": "tsc --project tsconfig.esm.json" | ||
}, | ||
@@ -35,25 +35,19 @@ "repository": { | ||
"jest": { | ||
"testEnvironment": "node", | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
] | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^23.3.1", | ||
"@types/node": "^10.7.1", | ||
"jest": "^23.5.0", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^23.1.4", | ||
"tslint": "^5.11.0", | ||
"tslint-config-prettier": "^1.15.0", | ||
"typescript": "^3.0.1" | ||
"@types/jest": "^24.0.11", | ||
"@types/node": "^11.12.0", | ||
"@typescript-eslint/eslint-plugin": "^1.5.0", | ||
"@typescript-eslint/parser": "^1.5.0", | ||
"eslint": "^5.15.3", | ||
"eslint-config-cheminfo": "^1.20.1", | ||
"eslint-config-cheminfo-typescript": "^3.0.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-jest": "^22.4.1", | ||
"jest": "^24.5.0", | ||
"rimraf": "^2.6.3", | ||
"ts-jest": "^24.0.0", | ||
"typescript": "^3.3.4000" | ||
}, | ||
@@ -60,0 +54,0 @@ "dependencies": { |
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
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
58040
9
13
1100