sequential-data-view-js
v0.1.1
Published
simple sequential binary reader
Downloads
4
Readme
SequentialDataView.js
SequentialDataView is a wrapper for the DataView low level interface for reading and withing binary data sequentially.
Quick Start
- Create an
SequentialDataView
object withnew SequentialDataView(arrayBuffer)
or the async static methodSequentialDataView.fromFile(file)
. - User the
get[binary-data-type]
methods to parse the contents, E.g.sequentialDataView.getUint8()
, this will progress the pointer position in the array buffer accordingly. - Call
sequentialDataView.pos()
to get the current pointer position orsequentialDataView.atEnd()
to che if has reached the end of the array buffer. - Call
sequentialDataView.seek(pos)
to set the current pointer position to skip ahead or go back.
// Module import
const { SequentialDataView } from 'sequential-data-view-js';
// Prepare buffer to parse.
const arrayBuffer = Uint8Array.from(atob('/wFZAQBYQA=='), c => c.charCodeAt(0)).buffer;
//
const sequentialDataView = new SequentialDataView();
// Parse buffer and show result
console.log(sequentialDataView.getUint8());//255
console.log(sequentialDataView.getUint16());//345
console.log(sequentialDataView.getUint32());//600
console.log(sequentialDataView.getInt8());//64
// jump back and rad the first byte as a signed 8bit int
sequentialDataView.seek(0);
console.log(sequentialDataView.getInt8());//-123
// Module import
const { SequentialDataView } from 'sequential-data-view-js';
// Prepare buffer to parse.
const arrayBuffer = Uint8Array.from(atob('/wFZAQBYQA=='), c => c.charCodeAt(0)).buffer;
//
const sequentialDataView = new SequentialDataView();
// Parse buffer and show result
console.log(sequentialDataView.getUint8());//255
console.log(sequentialDataView.getUint16());//345
console.log(sequentialDataView.getUint32());//600
console.log(sequentialDataView.getInt8());//64
// jump back and rad the first byte as a signed 8bit int
sequentialDataView.seek(0);
console.log(sequentialDataView.getInt8());//-123
Installation
You can install SequentialDataView.js
via npm:
npm install sequential-data-view-js
The npm package includes types.
Built With
- TypeScript
- RollUp
Author
👤 Juan Luis Palacios
- GitHub: @JuanLPalacios
- Twitter: @JuanLuisPalac20
- LinkedIn: LinkedIn
🤝 Contributing
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Show your support
Give a ⭐️ if you like this project!
📝 License
This project is MIT licensed.