Socket
Socket
Sign inDemoInstall

byte-data-stream

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byte-data-stream

Readable & writable byte data stream


Version published
Maintainers
1
Created
Source

byte-data-stream

Readable & writable byte data stream

Usage

const fs = require('fs');
const { ByteStream } = require('byte-data-stream');

let buf = fs.readFileSync('......'); // any ArrayBuffer or Uint8Array or nodejs Buffer
let stream = new ByteStream(buf);

stream.read_int8(); // read signed byte
stream.read_uint8(); // read unsigned byte
stream.read_bytes(8); // read many bytes
stream.read_int16(); // read signed big-endian 16-bit integer
stream.read_uint16(true); // read unsigned little-endian 16-bit integer
stream.read_var_uint(); // read unsigned big-endian varint
// ...

stream.write_int8(96); // write signed byte
stream.write_uint8(192); // write unsigned byte
stream.write_bytes([19,72,11,21,19,72,11,21]); // write many bytes
stream.write_int16(1972); // write signed big-endian 16-bit integer
stream.write_uint16(49861,true); // write unsigned little-endian 16-bit integer
stream.write_var_uint(92736296525); // write unsigned big-endian varint
// ...

All methods

// properties
stream.i; // position
stream.buffer; // ArrayBuffer

// methods for reading data
stream.read_int8();
stream.read_uint8();
stream.read_bytes(length);
stream.read_int16(little_endian);
stream.read_uint16(little_endian);
stream.read_int32(little_endian);
stream.read_uint32(little_endian);
stream.read_big_int64(little_endian);
stream.read_big_uint64(little_endian);
stream.read_float32(little_endian);
stream.read_float64(little_endian);
stream.read_var_int(little_endian,max_byte_length = Infinity);
stream.read_var_uint(little_endian,max_byte_length = Infinity);

// methods for writing data
stream.write_int8(val);
stream.write_uint8(val);
stream.write_bytes(bytes);
stream.write_int16(val,little_endian);
stream.write_uint16(val,little_endian);
stream.write_int32(val,little_endian);
stream.write_uint32(val,little_endian);
stream.write_big_int64(val,little_endian);
stream.write_big_uint64(val,little_endian);
stream.write_float32(val,little_endian);
stream.write_float64(val,little_endian);
stream.write_var_int(val,little_endian);
stream.write_var_uint(val,little_endian);

Keywords

FAQs

Package last updated on 13 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc