# it-length-prefixed

> Streaming length prefixed buffers with async iterables

Latest version **11.0.1** (published 2026-05-08) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install it-length-prefixed
pnpm add it-length-prefixed
yarn add it-length-prefixed
bun add it-length-prefixed
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 11.0.1 |
| Published | 2026-05-08 |
| First published | 2019-05-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 5 |
| Unpacked size | 106.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Author | Alan Shaw |
| Maintainers | achingbrain, alanshaw |
| Keywords | async, iterable, iterator, length-prefixed, length-prefixed-stream, varint |

## Links

- npm: https://www.npmjs.com/package/it-length-prefixed
- Repository: https://github.com/alanshaw/it-length-prefixed
- Homepage: https://github.com/alanshaw/it-length-prefixed#readme
- Issues: https://github.com/alanshaw/it-length-prefixed/issues
- npm.io page: https://npm.io/package/it-length-prefixed

## Dependencies (5)

- [it-reader](https://npm.io/package/it-reader.md) ^7.0.0
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^6.1.0
- [uint8-varint](https://npm.io/package/uint8-varint.md) ^3.0.0
- [uint8arraylist](https://npm.io/package/uint8arraylist.md) ^3.0.1
- [it-stream-types](https://npm.io/package/it-stream-types.md) ^2.0.1

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 11.0.1 (latest) — 2026-05-08
- 11.0.0 — 2026-05-07
- 10.0.2 — 2026-05-07
- 10.0.1 — 2025-02-13
- 10.0.0 — 2025-02-03
- 9.1.1 — 2025-01-24
- 9.1.0 — 2024-08-08
- 9.0.5 — 2024-08-07
- 9.0.4 — 2023-12-30
- 9.0.3 — 2023-08-16
- 9.0.2 — 2023-08-16
- 9.0.1 — 2023-04-18
- 9.0.0 — 2023-03-31
- 8.0.4 — 2022-12-22
- 8.0.3 — 2022-10-12
- … 18 more at https://npm.io/package/it-length-prefixed/versions

## README

# it-length-prefixed

[![codecov](https://img.shields.io/codecov/c/github/alanshaw/it-length-prefixed.svg?style=flat-square)](https://codecov.io/gh/alanshaw/it-length-prefixed)
[![CI](https://img.shields.io/github/actions/workflow/status/alanshaw/it-length-prefixed/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/alanshaw/it-length-prefixed/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> Streaming length prefixed buffers with async iterables

# About

<!--

!IMPORTANT!

Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.

To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts

To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.

-->

Encode/decode streams of bytes with length-prefixes.

## Example

```js
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

- <https://alanshaw.github.io/it-length-prefixed>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](https://github.com/alanshaw/it-length-prefixed/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/alanshaw/it-length-prefixed/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# 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.

---
_Source: https://npm.io/package/it-length-prefixed · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
