Corrode
Extends:
Corrode A batteries-included library for reading your binary data. It helps you converting that blob-mess into readable data.
It inherits from CorrodeBase to make the abstraction between these two components more obvious. CorrodeBase does all the dirty low-level work reading bytes, managing jobs, etc. This class however doesn't manipulate the CorrodeBase#jobs-array or messes in other ways with the CorrodeBase#jobLoop.
This class builds on loop and tap to provide more complex functionality.
Test:
Static Member Summary
Static Public Members | ||
public static |
assertions-object |
|
public static |
object holding all the user-defined extensions. |
|
public static |
mappers-object |
|
public static |
|
Static Method Summary
Static Public Methods | ||
public static |
addExtension(name: string, fn: function(...args: *)) adds an extension to corrode. |
Constructor Summary
Public Constructor | ||
public |
constructor(options: object) initializes mappers, assertions and extensions |
Member Summary
Public Members | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
Method Summary
Public Methods | ||
public |
helper utility logging the current vars |
|
public |
fromBuffer(buffer: Buffer, done: function(error: *, data: object)): Corrode helper utility, parsing a given buffer async |
|
public |
pushes a pointer-job onto the job-array returns an item of an accessable type (object property, array element) being given an accessable type. |
|
public |
sets CorrodeBase#streamOffset to a given absolute position like skip, but absolute If you want to set the offset to something lower than the current offset, you should enable CorrodeBase#isSeeking asap, as otherwise there's no guarantee that the buffer is still available or already flushed. |
|
public |
repeat(name: string, length: number, fn: function(end: function, discard: function, i: number)): Corrode pushes a repeat-job onto the job-array a repeat-job repeats itself a given number of times and then ends. |
|
public |
terminatedBuffer(name: string, terminator: number, discardTerminator: boolean): Corrode pushes a terminatedBuffer-job onto the job-array The returned Buffer will be a slice (not a copy) of the underlying CorrodeBase#streamBuffer internally this method uses the isSeeking-property to prevent flushing of the underlying buffer. |
|
public |
terminatedString(name: string, terminator: number, discardTerminator: boolean, encoding: string): Corrode pushes a terminatedString-job onto the job-array Returns a string ranging from the current offset until the given terminator is found |
Inherited Summary
From class CorrodeBase | ||
public static |
static constant for big endian |
|
public static |
static constant for little endian |
|
public static |
Defaults Object for available options CorrodeBase#constructor |
|
public get |
get variables of the current stack |
|
public set |
replace the current value |
|
public |
offset in the current running chunk (CorrodeBase#streamBuffer) |
|
public |
indicates whether automatic flushes are disabled |
|
public |
indicates whether only pops are getting processed |
|
public |
array holding the jobs which are to be processed |
|
public |
|
|
public |
available primitve jobs. |
|
public |
streamBuffer: BufferList internal buffer for stream-chunks not yet processable |
|
public |
offset in the whole piped stream |
|
public |
the VariableStack holding the layers and variables of this instance |
|
public |
buffer(name: string, length: number | string): CorrodeBase pushes a buffer-job onto the job-array the buffer-job will read a buffer with the given length starting at the current offset CorrodeBase#bufferOffset. |
|
public |
double(name: string): CorrodeBase push a double job with default endianness (CorrodeBase#options.endianness) onto the job-array |
|
public |
doublebe(name: string): CorrodeBase push a double job with big endianness onto the job-array |
|
public |
doublele(name: string): CorrodeBase push a double job with little endianness onto the job-array |
|
public |
re-starts the jobLoop with the job-list cleaned from any read jobs CorrodeBase#removeReadJobs CorrodeBase#isUnwinding |
|
public |
float(name: string): CorrodeBase push a float job with default endianness (CorrodeBase#options.endianness) onto the job-array |
|
public |
floatbe(name: string): CorrodeBase push a float job with big endianness onto the job-array |
|
public |
floatle(name: string): CorrodeBase push a float job with little endianness onto the job-array |
|
public |
int16(name: string): CorrodeBase push a int16 (signed) job with default endianness (CorrodeBase#options.endianness) onto the job-array |
|
public |
int16be(name: string): CorrodeBase push a int16 (signed) job with big endianness onto the job-array |
|
public |
int16le(name: string): CorrodeBase push a int16 (signed) job with little endianness onto the job-array |
|
public |
int32(name: string): CorrodeBase push a int32 (signed) job with default endianness (CorrodeBase#options.endianness) onto the job-array |
|
public |
int32be(name: string): CorrodeBase push a int32 (signed) job with big endianness onto the job-array |
|
public |
int32le(name: string): CorrodeBase push a int32 (signed) job with little endianness onto the job-array |
|
public |
int64(name: string): CorrodeBase push a int64 (signed) job with default endianness (CorrodeBase#options.endianness) onto the job-array note that in64 may be unprecise, due to number-values being double in js |
|
public |
int64be(name: string): CorrodeBase push a int64 (signed) job with big endianness onto the job-array note that in64 may be unprecise, due to number-values being double in js |
|
public |
int64le(name: string): CorrodeBase push a int64 (signed) job with little endianness onto the job-array note that in64 may be unprecise, due to number-values being double in js |
|
public |
int8(name: string): CorrodeBase push a int8 (signed) job onto the job-array |
|
public |
int8be(name: string): CorrodeBase this method was deprecated. int8 needs no endianness, use int8() instead
push a int8 (signed) job onto the job-array |
|
public |
int8le(name: string): CorrodeBase this method was deprecated. int8 needs no endianness, use int8() instead
push a int8 (signed) job onto the job-array |
|
public |
jobLoop() internal function to process the array of jobs still remaing. |
|
public |
push a loop-job onto the job-array a loop-job is a special kind of job allowing the developer to create loops in the current job-array. |
|
public |
pop(): CorrodeBase push a pop-job onto the job-array the pop-job pops a layer from CorrodeBase#varStack. |
|
public |
push(name: string, value: *): CorrodeBase push a push-job onto the job-array the push-job pushes a new layer onto CorrodeBase#varStack. |
|
public |
remove all jobs from CorrodeBase#jobs with the ability to re-add them back later. |
|
public |
purges all jobs from the job-queue, which need to read from the stream |
|
public |
skip(length: number | string): CorrodeBase push a skip-job onto the job-array skip-jobs allow the developer to skip a given number of bytes. |
|
public |
pushes a string-job onto the job-array the string-job will read a string with the given length starting at the current offset CorrodeBase#bufferOffset |
|
public |
tap(name: string, callback: function(...args: *), args: Array): CorrodeBase push a tap-job onto the job-array a tap-job is a special kind of job allowing the developer to peek into the current variables and creating more complex structures and behaviour based on available information. |
|
public |
uint16(name: string): CorrodeBase push a uint16 (unsigned) job with default endianness (CorrodeBase#options.endianness) onto the job-array |
|
public |
uint16be(name: string): CorrodeBase push a uint16 (unsigned) job with big endianness onto the job-array |
|
public |
uint16le(name: string): CorrodeBase push a uint16 (unsigned) job with little endianness onto the job-array |
|
public |
uint32(name: string): CorrodeBase push a uint32 (unsigned) job with default endianness (CorrodeBase#options.endianness) onto the job-array |
|
public |
uint32be(name: string): CorrodeBase push a uint32 (unsigned) job with big endianness onto the job-array |
|
public |
uint32le(name: string): CorrodeBase push a uint32 (unsigned) job with little endianness onto the job-array |
|
public |
uint64(name: string): CorrodeBase push a uint64 (unsigned) job with default endianness (CorrodeBase#options.endianness) onto the job-array note that in64 may be unprecise, due to number-values being double in js |
|
public |
uint64be(name: string): CorrodeBase push a uint64 (unsigned) job with big endianness onto the job-array note that in64 may be unprecise, due to number-values being double in js |
|
public |
uint64le(name: string): CorrodeBase push a uint64 (unsigned) job with little endianness onto the job-array note that in64 may be unprecise, due to number-values being double in js |
|
public |
uint8(name: string): CorrodeBase push a uint8 (unsigned) job onto the job-array |
|
public |
uint8be(name: string): CorrodeBase this method was deprecated. uint8 needs no endianness, use uint8() instead
push a uint8 (unsigned) job onto the job-array |
|
public |
uint8le(name: string): CorrodeBase this method was deprecated. uint8 needs no endianness, use uint8() instead
push a uint8 (unsigned) job onto the job-array |
|
private |
_flush(done: *) finish remaining jobs if finishJobsOnEOF is enabled |
|
private |
_moveOffset(by: *) utility method to move both CorrodeBase#chunkOffset and CorrodeBase#streamOffset by a given amount of bytes |
|
private |
_pushJob(name: *, type: *, length: *, endianness: *): CorrodeBase utility method to push a new job onto the job-array |
|
private |
_transform(chunk: *, encoding: *, done: *): * add a new chunk to the internal buffer and process remaining jobs this TransformStream won't call the push-method as it is not able to guarantee correct ouptut while still reading data. this depends not on corrode, but on the way you use it. |
Static Public Members
Static Public Methods
public static addExtension(name: string, fn: function(...args: *)) source
adds an extension to corrode. extensions are user-defined functions allowing you to better abstract upon corrode an extension can accept parameters and receives the current available variables. it can either directly return values or read them from the buffer with corrode's functions.
Example:
Corrode.addExtension('foo', function(arg1){ this.uint8(arg1); });
(new Corrode()).ext.foo('foo_value', 'arg1');
Corrode.addExtension('bar', function(arg1){ return this.vars[arg1] * this.vars[arg1] });
(new Corrode()).ext.bar('bar_value', 'arg1')
Public Constructors
public constructor(options: object) source
initializes mappers, assertions and extensions
Override:
CorrodeBase#constructorParams:
Name | Type | Attribute | Description |
options | object |
Public Members
public isSeeking: boolean source
indicates whether automatic flushes are disabled
Override:
CorrodeBase#isSeekingPublic Methods
public fromBuffer(buffer: Buffer, done: function(error: *, data: object)): Corrode source
helper utility, parsing a given buffer async
public pointer(name: string, obj: Object | Array, type: string): Corrode source
pushes a pointer-job onto the job-array returns an item of an accessable type (object property, array element) being given an accessable type. the offset used to access the accessable type is determined by reading a value of the given type
Test:
public position(offset: number | string): Corrode source
sets CorrodeBase#streamOffset to a given absolute position like skip, but absolute If you want to set the offset to something lower than the current offset, you should enable CorrodeBase#isSeeking asap, as otherwise there's no guarantee that the buffer is still available or already flushed.
Params:
Name | Type | Attribute | Description |
offset | number | string | as number or as string referencing a variable from CorrodeBase#vars |
Test:
public repeat(name: string, length: number, fn: function(end: function, discard: function, i: number)): Corrode source
pushes a repeat-job onto the job-array a repeat-job repeats itself a given number of times and then ends. it's also possible to end the job prematurely or discard it. This is nothing else than a proxy to CorrodeBase#loop
Params:
Name | Type | Attribute | Description |
name | string |
|
name of the new variable-layer. if none is provided, the current layer will be used |
length | number | iteration-count as number or as string referencing a variable from CorrodeBase#vars |
|
fn | function(end: function, discard: function, i: number) | called until |
Test:
public terminatedBuffer(name: string, terminator: number, discardTerminator: boolean): Corrode source
pushes a terminatedBuffer-job onto the job-array The returned Buffer will be a slice (not a copy) of the underlying CorrodeBase#streamBuffer internally this method uses the isSeeking-property to prevent flushing of the underlying buffer.
Test:
public terminatedString(name: string, terminator: number, discardTerminator: boolean, encoding: string): Corrode source
pushes a terminatedString-job onto the job-array Returns a string ranging from the current offset until the given terminator is found
Params:
Name | Type | Attribute | Description |
name | string | name of the string-variable |
|
terminator | number |
|
uint8-value indicating the end of the buffer |
discardTerminator | boolean |
|
whether or not to include the terminator in the resulting buffer |
encoding | string |
|
encoding encoding used to decode the string, defaults to 'utf8'. available encodings can be found here https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings |