(ES6) ES6 (2016)

TypedArr (TB08)

   1:  // Assume 'buffer' contains the binary data of a file (implementation for receiving data depends on specific context)
   2:  const buffer = new ArrayBuffer(20); // For example.
   3:  const view = new DataView(buffer);
   4:  
   5:  view.setUint16(0, 0x1234, true); // 16-bit integer at offset 0
   6:  view.setUint32(2, 0x56789ABC, true); // 32-bit integer at offset 2
   7:  
   8:  const header = view.getUint32(0);   // Read a 32-bit unsigned integer header at offset 0
   9:  const version = view.getUint8(4);    // Read an 8-bit unsigned integer version at offset 4
  10:  const timestamp = view.getFloat64(5, false); // Read a 64-bit float timestamp (big-endian)
  11:  
  12:  console.log (header,version,timestamp)



Parsing a Binary File

This code simulates reading a header, version number, and a timestamp at different places in a binary file.
The order of bytes (endianness) during read operations must match the endianness of how these values are stored in the binary format.

873643162 120 1.8347988927920572e+106





TypedArr context:






ES6 context:




Binary context:



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/JavascriptES6/TB08.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>