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:
- (2024) Notes about JS Closures. #ES6
- (2024) Notes about Javascript asynchronous programming. #ES6
- (2022) Modern Javascript books #ES6 #Doc
- (2021) JS learning start point #ES6
- (2021) Maximilian Schwarzmüller Javascript lecture #ES6
- (2021) Javascript interview question from Happy Rawat #ES6
- (2021) Javascript tests #ES6
- (2016) New unique features of Javascript (updated). #ES6
Binary context:
- (2019) How to change image Exif metadata #Binary
- (2018) З'ясування алгоритмів оновлення Documat-CD SEB. #Binary
- (2016) JS6 Typed Array #ES6 #Binary
- (2015) Сховище графіки на SQL FileStream та канал браузеру multipart/form-data. #Sql #WebServiceClient #Binary
- (2012) Робота з байтами у VB.NET - ChrW, BitConverter.ToInt32, Convert.ToInt32, Byte.Parse, ToString("X2") / AllowHexSpecifier, GetBytes/GetString, New Byte(N) {}, UInt32 = &H33 #Binary #NetCommon
- (2005) DumpExe - утилитка дампирования структуры NET-сборок с открытым исходным текстом. #Binary #WinDesktop
- (2003) DVD - формат и обзор техник работы с ним. #Binary
- (2002) PE - формат исполняемого файла. #Binary
- (2002) FRX-парсер - моя утилитка для выкусывания рисунков из шестерочного FRX-файла. #WinDesktop #Vb6 #Binary
Comments (
)

Link to this page:
http://www.vb-net.com/JavascriptES6/TB08.htm
|