From CommonJS Spec Wiki
< Binary‎ | C(Redirected from CommonJS/Binary/C/Unpacking)
Jump to: navigation, search

These methods are related to unpacking, they were be removed from the proposal in favor of specifying that at a higher layer but are here for reference until we write a proposal for unpacking of binary data.

blob.integerAt(offset, size=1, signed=false, networkEndian=false);
Extracts an integer out of a blob. Arguments may control the byte size extracted whether the number is signed or unsigned, and whether or not the byte is in networkEndian or not. The default is to return a single unsigned byte in the form of an integer in the range 0..255.
blob.floatAt(offset, size);
Extracts a float out of a blob. This method requires a size argument of either 4 (floats) or 8 (doubles) to extract a number and should generate a TypeError if passed invalid params.
blob.stringAt(offset, size, fromCharset=UTF-16);
Extracts a string out from a blob. This method is similar to if you had done blob.slice(offset, size).toString(fromCharset||"UTF-16");.