DataStream reads scalars, arrays and structs of data from an ArrayBuffer. It's like a file-like DataView on steroids.
ArrayBuffer to read from.
Offset from arrayBuffer beginning for the DataStream.
DataStream.BIG_ENDIAN or DataStream.LITTLE_ENDIAN (the default).
Seek position where readStruct ran into a problem. Useful for debugging struct parsing.
Big-endian const to use as default endianness.
Little-endian const to use as default endianness.
Native endianness. Either DataStream.BIG_ENDIAN or DataStream.LITTLE_ENDIAN depending on the platform endianness.
Set/get the backing ArrayBuffer of the DataStream object. The setter updates the DataView to point to the new buffer.
Set/get the backing ArrayBuffer of the DataStream object. The setter updates the DataView to point to the new buffer.
Returns the byte length of the DataStream object.
Set/get the byteOffset of the DataStream object. The setter updates the DataView to point to the new byteOffset.
Set/get the byteOffset of the DataStream object. The setter updates the DataView to point to the new byteOffset.
Set/get the backing DataView of the DataStream object. The setter updates the buffer and byteOffset to point to the DataView values.
Set/get the backing DataView of the DataStream object. The setter updates the buffer and byteOffset to point to the DataView values.
Whether to extend DataStream buffer when trying to write beyond its size. If set, the buffer is reallocated to twice its current size until the requested write fits the buffer.
Whether to extend DataStream buffer when trying to write beyond its size. If set, the buffer is reallocated to twice its current size until the requested write fits the buffer.
Returns true if the DataStream seek pointer is at the end of buffer and there's no more data to read.
True if the seek pointer is at the end of the buffer.
Maps a Float32Array into the DataStream buffer, swizzling it to native endianness in-place. The current offset from the start of the buffer needs to be a multiple of element size, just like with typed array views.
Nice for quickly reading in data. Warning: potentially modifies the buffer contents.
Number of elements to map.
Endianness of the data to read.
Float32Array to the DataStream backing buffer.
Maps a Float64Array into the DataStream buffer, swizzling it to native endianness in-place. The current offset from the start of the buffer needs to be a multiple of element size, just like with typed array views.
Nice for quickly reading in data. Warning: potentially modifies the buffer contents.
Number of elements to map.
Endianness of the data to read.
Float64Array to the DataStream backing buffer.
Maps an Int16Array into the DataStream buffer, swizzling it to native endianness in-place. The current offset from the start of the buffer needs to be a multiple of element size, just like with typed array views.
Nice for quickly reading in data. Warning: potentially modifies the buffer contents.
Number of elements to map.
Endianness of the data to read.
Int16Array to the DataStream backing buffer.
Maps an Int32Array into the DataStream buffer, swizzling it to native endianness in-place. The current offset from the start of the buffer needs to be a multiple of element size, just like with typed array views.
Nice for quickly reading in data. Warning: potentially modifies the buffer contents.
Number of elements to map.
Endianness of the data to read.
Int32Array to the DataStream backing buffer.
Maps an Int8Array into the DataStream buffer.
Nice for quickly reading in data.
Number of elements to map.
Int8Array to the DataStream backing buffer.
Maps a Uint16Array into the DataStream buffer, swizzling it to native endianness in-place. The current offset from the start of the buffer needs to be a multiple of element size, just like with typed array views.
Nice for quickly reading in data. Warning: potentially modifies the buffer contents.
Number of elements to map.
Endianness of the data to read.
Uint16Array to the DataStream backing buffer.
Maps a Uint32Array into the DataStream buffer, swizzling it to native endianness in-place. The current offset from the start of the buffer needs to be a multiple of element size, just like with typed array views.
Nice for quickly reading in data. Warning: potentially modifies the buffer contents.
Number of elements to map.
Endianness of the data to read.
Uint32Array to the DataStream backing buffer.
Maps a Uint8Array into the DataStream buffer.
Nice for quickly reading in data.
Number of elements to map.
Uint8Array to the DataStream backing buffer.
Reads an 8-bit int from the DataStream with the offset.
The offset.
The read number.
Read null-terminated string of desired length from the DataStream. Truncates the returned string so that the null byte is not a part of it.
The length of the string to read.
The read string.
Reads a 32-bit float from the DataStream with the desired endianness.
Endianness of the number.
The read number.
Reads a Float32Array of desired length and endianness from the DataStream.
Number of elements to map.
Endianness of the data to read.
The read Float32Array.
Reads a 64-bit float from the DataStream with the desired endianness.
Endianness of the number.
The read number.
Reads a Float64Array of desired length and endianness from the DataStream.
Number of elements to map.
Endianness of the data to read.
The read Float64Array.
Reads a 32-bit int from the DataStream with the offset.
The offset.
The read number.
Reads a 16-bit int from the DataStream with the desired endianness.
Endianness of the number.
The read number.
Reads an Int16Array of desired length and endianness from the DataStream.
Number of elements to map.
Endianness of the data to read.
The read Int16Array.
Reads a 32-bit int from the DataStream with the desired endianness.
Endianness of the number.
The read number.
Reads an Int32Array of desired length and endianness from the DataStream.
Number of elements to map.
Endianness of the data to read.
The read Int32Array.
Reads an 8-bit int from the DataStream.
The read number.
Reads an Int8Array of desired length from the DataStream.
Number of elements to map.
The read Int8Array.
Reads a 16-bit int from the DataStream with the offset
The offset.
The read number.
Read a string of desired length and encoding from the DataStream.
The length of the string to read in bytes.
The encoding of the string data in the DataStream. Defaults to ASCII.
The read string.
Read UCS-2 string of desired length and offset from the DataStream.
The offset.
The length of the string to read.
The read string.
Reads a struct of data from the DataStream. The struct is defined as a flat array of [name, type]-pairs. See the example below:
ds.readStruct([ 'headerTag', 'uint32', // Uint32 in DataStream endianness. 'headerTag2', 'uint32be', // Big-endian Uint32. 'headerTag3', 'uint32le', // Little-endian Uint32. 'array', ['[]', 'uint32', 16], // Uint32Array of length 16. 'array2Length', 'uint32', 'array2', ['[]', 'uint32', 'array2Length'] // Uint32Array of length array2Length ]);
The possible values for the type are as follows:
// Number types
// Unsuffixed number types use DataStream endianness. // To explicitly specify endianness, suffix the type with // 'le' for little-endian or 'be' for big-endian, // e.g. 'int32be' for big-endian int32.
'uint8' -- 8-bit unsigned int 'uint16' -- 16-bit unsigned int 'uint32' -- 32-bit unsigned int 'int8' -- 8-bit int 'int16' -- 16-bit int 'int32' -- 32-bit int 'float32' -- 32-bit float 'float64' -- 64-bit float
// String types 'cstring' -- ASCII string terminated by a zero byte. 'string:N' -- ASCII string of length N, where N is a literal integer. 'string:variableName' -- ASCII string of length $variableName, where 'variableName' is a previously parsed number in the current struct. 'string,CHARSET:N' -- String of byteLength N encoded with given CHARSET. 'u16string:N' -- UCS-2 string of length N in DataStream endianness. 'u16stringle:N' -- UCS-2 string of length N in little-endian. 'u16stringbe:N' -- UCS-2 string of length N in big-endian.
// Complex types [name, type, name_2, type_2, ..., name_N, type_N] -- Struct function(dataStream, struct) {} -- Callback function to read and return data. {get: function(dataStream, struct) {}, set: function(dataStream, struct) {}} -- Getter/setter functions to read and return data, handy for using the same struct definition for reading and writing structs. ['[]', type, length] -- Array of given type and length. The length can be either a number, a string that references a previously-read field, or a callback function(struct, dataStream, type){}. If length is '*', reads in as many elements as it can.
Struct definition object.
The read struct. Null if failed to read struct.
Reads an object of type t from the DataStream, passing struct as the thus-far read struct to possible callbacks that refer to it. Used by readStruct for reading in the values, so the type is one of the readStruct types.
Type of the object to read.
Struct to refer to when resolving length references and for calling callbacks.
Returns the object on successful read, null on unsuccessful.
Read UCS-2 string of desired length and endianness from the DataStream.
The length of the string to read.
The endianness of the string data in the DataStream.
The read string.
Reads a 16-bit unsigned int from the DataStream with the desired endianness.
Endianness of the number.
The read number.
Reads a Uint16Array of desired length and endianness from the DataStream.
Number of elements to map.
Endianness of the data to read.
The read Uint16Array.
Reads a 32-bit unsigned int from the DataStream with the desired endianness.
Endianness of the number.
The read number.
Reads a Uint32Array of desired length and endianness from the DataStream.
Number of elements to map.
Endianness of the data to read.
The read Uint32Array.
Reads an 8-bit unsigned int from the DataStream.
The read number.
Reads a Uint8Array of desired length from the DataStream.
Number of elements to map.
The read Uint8Array.
Saves the DataStream contents to the given filename. Uses Chrome's anchor download property to initiate download.
Filename to save as.
Sets the DataStream read/write position to given position. Clamps between 0 and DataStream length.
Position to seek to.
Writes a null-terminated string to DataStream and zero-pads it to length bytes. If length is not given, writes the string followed by a zero. If string is longer than length, the written part of the string does not have a trailing zero.
The string to write.
The number of characters to write.
Writes a 32-bit float to the DataStream with the desired endianness.
Number to write.
Endianness of the number.
Writes a Float32Array of specified endianness to the DataStream.
The array to write.
Endianness of the data to write.
Writes a 64-bit float to the DataStream with the desired endianness.
Number to write.
Endianness of the number.
Writes a Float64Array of specified endianness to the DataStream.
The array to write.
Endianness of the data to write.
Writes a 16-bit int to the DataStream with the desired endianness.
Number to write.
Endianness of the number.
Writes an Int16Array of specified endianness to the DataStream.
The array to write.
Endianness of the data to write.
Writes a 32-bit int to the DataStream with the desired endianness.
Number to write.
Endianness of the number.
Writes an Int32Array of specified endianness to the DataStream.
The array to write.
Endianness of the data to write.
Writes an 8-bit int to the DataStream.
Number to write.
Writes an Int8Array to the DataStream.
The array to write.
Writes a string of desired length and encoding to the DataStream.
The string to write.
The encoding for the written string data. Defaults to ASCII.
The number of characters to write.
Writes a struct to the DataStream. Takes a structDefinition that gives the types and a struct object that gives the values. Refer to readStruct for the structure of structDefinition.
Type definition of the struct.
The struct data object.
Writes object v of type t to the DataStream.
Type of data to write.
Value of data to write.
Struct to pass to write callback functions.
Write a UCS-2 string of desired endianness to the DataStream. The lengthOverride argument lets you define the number of characters to write. If the string is shorter than lengthOverride, the extra space is padded with zeroes.
The string to write.
The endianness to use for the written string data.
The number of characters to write.
Writes a 16-bit unsigned int to the DataStream with the desired endianness.
Number to write.
Endianness of the number.
Writes a Uint16Array of specified endianness to the DataStream.
The array to write.
Endianness of the data to write.
Writes a 32-bit unsigned int to the DataStream with the desired endianness.
Number to write.
Endianness of the number.
Writes a Uint32Array of specified endianness to the DataStream.
The array to write.
Endianness of the data to write.
Writes an 8-bit unsigned int to the DataStream.
Number to write.
Writes a Uint8Array to the DataStream.
The array to write.
Generated using TypeDoc
This DataStream is for internal use.