šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

cobs-transform-streams

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cobs-transform-streams

Encode or decode using COBS (Consistent Overhead Byte Stuffing)

0.1.0
latest
Source
npm
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
Ā 
Created
Source

Consistent Overhead Byte Stuffing Transform Streams

Encode or decode using COBS (Consistent Overhead Byte Stuffing) using COBS Transfors Streams (https://streams.spec.whatwg.org/#ts-class)

More info: https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing

Example

Instantiation and use

  const decoder = new TransformStream(new COBSDecoderTransformer);

Reading data

  const reader = decoder.readable.getReader();

  function processData(chunk) {
    let { done, value } = chunk;
    if (done) {
      return;
    }

    const view = new DataView(value.buffer);

    // do stuff with data.
    return reader.read().then(processData);
  };

  reader.read().then(processData);

Writing data

  const writer = decoder.readable.getWriter();

  async readFromDevice() {
    // Example using Web USB to get 32 bytes on endpoint 5
    const transfer = await this.device.transferIn(5, 32);

    const data = new Uint8Array(transfer.data.buffer);
    writer.write(data);

    this.readFromDevice();
  }

Keywords

cobs

FAQs

Package last updated on 11 Jan 2019

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