jBinary Methods (original) (raw)

Reading/Writing

var firstInt = binary.read('uint32'); // uint32 value at offset 0 var secondInt = binary.read('uint32'); // following uint32 value at offset 4 var byteAtOffset100 = binary.read('uint8', 100); // uint8 value at custom position var thirdInt = binary.read('uint32'); // third uint32 value at offset 8 (since read operation with custom position didn't move internal pointer)

binary.write('uint32', 1); // writing uint32 value of 1 at offset 0 binary.write('uint32', 2); // writing uint32 value of 2 at offset 4 binary.write('uint8', 0xff, 100); // writing uint8 value of 255 at offset 100 binary.write('uint32', 3); // writing uint32 value of 3 at offset 8

Position methods

var currentPos = binary.tell();

binary.seek(100); // just went to offset 100 var intAt200 = binary.seek(200, function () { return this.binary.read('int32') }); // go to offset 200, get int32 value there and return back to offset 100

binary.skip(1); // just skip one byte we are not interested in var intAfter8 = binary.skip(8, function () { return this.binary.read('int32') }); // go 8 bytes forward, get int32 value there and return back

Instance helpers

var pointerSlice = binary.slice(10, 20); // now you can manipulate on this jBinary instance and all the changes will be mirrored to original binary's data, but with new bound check rules var copySlice = binary.slice(10, 20, true); // now you can manipulate on this jBinary instance as on absolutely new one and any data changes will stay isolated from original binary

var binary = someExternalBinary.as(TAR); // casting external jBinary instance with no or with irrelevant typeset to TAR typeSet object (any operations including both data and pointer manipulations will affect both instances).

Add a custom footer