Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

it-length-prefixed

alanshaw109.6kApache-2.0 OR MIT9.1.1TypeScript support: included

Streaming length prefixed buffers with async iterables

async, iterable, iterator, length-prefixed, length-prefixed-stream, varint

readme

it-length-prefixed

codecov CI

Streaming length prefixed buffers with async iterables

About

Encode/decode streams of bytes with length-prefixes.

Example

import { pipe } from 'it-pipe'
import * as lp from 'it-length-prefixed'

const encoded = []

// encode
await pipe(
  [uint8ArrayFromString('hello world')],
  (source) => lp.encode(source),
  async source => {
    for await (const chunk of source) {
      encoded.push(chunk.slice()) // (.slice converts Uint8ArrayList to Uint8Array)
    }
  }
)

console.log(encoded)
// => [Buffer <0b 68 65 6c 6c 6f 20 77 6f 72 6c 64>]

const decoded = []

// decode
await pipe(
  encoded, // e.g. from above
  (source) => lp.decode(source),
  async source => {
    for await (const chunk of source) {
      decoded.push(chunk.slice()) // (.slice converts Uint8ArrayList to Uint8Array)
    }
  }
)

console.log(decoded)
// => [Buffer <68 65 6c 6c 6f 20 77 6f 72 6c 64>]

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

changelog

9.1.1 (2025-01-24)

Dependencies

  • dev: bump aegir from 44.1.4 to 45.0.8 (#134) (a12e000)

9.1.0 (2024-08-08)

Features

  • add custom errors and remove err-code (#129) (7b845bd)

9.0.5 (2024-08-07)

Dependencies

  • dev: bump aegir from 40.0.13 to 44.1.0 (#128) (b92db93)

9.0.4 (2023-12-30)

Dependencies

  • bump uint8arrays from 4.0.10 to 5.0.1 (#116) (356d085)

9.0.3 (2023-08-16)

Dependencies

9.0.2 (2023-08-16)

Trivial Changes

  • add or force update .github/workflows/js-test-and-release.yml (#93) (740ff48)
  • delete templates [skip ci] (#92) (92a563c)

Dependencies

  • dev: bump aegir from 38.1.8 to 40.0.0 (#91) (68a809e)

9.0.1 (2023-04-18)

Dependencies

  • bump it-stream-types from 1.0.5 to 2.0.1 (#80) (3b75441)

9.0.0 (2023-03-31)

⚠ BREAKING CHANGES

  • a synchronous generator will be returned when a synchronous iterator is passed

Bug Fixes

  • do not create unnecessary async work (#74) (e29ab76)

8.0.4 (2022-12-22)

Documentation

8.0.3 (2022-10-12)

Dependencies

  • update uint8arrays from 3.x.x to 4.x.x (#49) (26660ea)

Trivial Changes

8.0.2 (2022-07-30)

Bug Fixes

8.0.1 (2022-07-28)

Bug Fixes

8.0.0 (2022-07-28)

⚠ BREAKING CHANGES

  • Uint8Arrays are now yielded instead of Uint8Arrays

Features

Dependencies

  • dev: update aegir and it-pushable (#44) (a67205e)

7.0.1 (2022-03-08)

Bug Fixes

  • do not create an array to pass in to uint8arraylist (#22) (94c4f03)

7.0.0 (2022-02-16)

⚠ BREAKING CHANGES

  • where BufferLists were returned, now Uint8ArrayLists are

Bug Fixes

6.0.1 (2022-01-13)

Bug Fixes

6.0.0 (2022-01-13)

⚠ BREAKING CHANGES

  • switch to named exports, ESM only

Features

5.0.3 (2021-07-07)

Bug Fixes

5.0.2 (2021-04-09)

Bug Fixes

5.0.1 (2021-04-09)

Bug Fixes

4.0.0 (2021-04-01)

3.1.0 (2020-07-27)

Features

3.0.1 (2020-03-18)

Bug Fixes

3.0.0 (2019-11-13)

Features

BREAKING CHANGES

  • Additional validation now checks for messages with a length that is too long to prevent a possible DoS attack. The error code ERR_MSG_TOO_LONG has changed to ERR_MSG_DATA_TOO_LONG and the error code ERR_MSG_LENGTH_TOO_LONG has been added.

License: MIT Signed-off-by: Alan Shaw alan.shaw@protocol.ai

2.0.0 (2019-09-26)

1.1.0 (2019-08-13)

Features

  • encode single and optional decode onLength/onData callbacks (#1) (ce68bc8)

1.0.0 (2019-05-07)

Bug Fixes

  • badgers (d2cec17)
  • decode and add test (987f8f6)
  • decode fixes and e2e tests (d4020df)
  • do not slice on bufer and data length equal (3def7c8)
  • fixes and tests (a26c5e8)
  • more fix badgers (7bbfc93)
  • properly handle backpressure (cf47d04)
  • sync streams and empty streams (33e3a64)
  • use default max length properly (182f3ed)

Features

  • add fixed prefix length as an option (c93f850)
  • add maxLength to allow controlling max buffer length during decode (7810ade)
  • encode + tests (d5f6d03)
  • improve tests and guards for failure cases (2c43d59)
  • maybe this decode function will work (3c0efc7)
  • decode: add decodeFromReader method (729dc2e)