{"name":"it-length-prefixed","version":"8.0.4","description":"Streaming length prefixed buffers with async iterables","author":{"name":"Alan Shaw"},"license":"Apache-2.0 OR MIT","homepage":"https://github.com/alanshaw/it-length-prefixed#readme","repository":{"type":"git","url":"git+https://github.com/alanshaw/it-length-prefixed.git"},"bugs":{"url":"https://github.com/alanshaw/it-length-prefixed/issues"},"keywords":["async","iterable","iterator","length-prefixed","length-prefixed-stream","varint"],"engines":{"node":">=16.0.0","npm":">=7.0.0"},"type":"module","types":"./dist/src/index.d.ts","typesVersions":{"*":{"*":["*","dist/*","dist/src/*","dist/src/*/index"],"src/*":["*","dist/*","dist/src/*","dist/src/*/index"]}},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"},"./decode":{"types":"./dist/src/decode.d.ts","import":"./dist/src/decode.js"},"./encode":{"types":"./dist/src/encode.d.ts","import":"./dist/src/encode.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"sourceType":"module"},"ignorePatterns":["benchmarks"]},"release":{"branches":["master"],"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"breaking":true,"release":"major"},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"clean":"aegir clean","lint":"aegir lint","dep-check":"aegir dep-check","build":"aegir build","test":"aegir test","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","test:node":"aegir test -t node --cov","test:electron-main":"aegir test -t electron-main","release":"aegir release","docs":"aegir docs"},"dependencies":{"err-code":"^3.0.1","it-stream-types":"^1.0.4","uint8-varint":"^1.0.1","uint8arraylist":"^2.0.0","uint8arrays":"^4.0.2"},"devDependencies":{"@types/varint":"^6.0.0","aegir":"^37.4.5","iso-random-stream":"^2.0.0","it-all":"^2.0.0","it-block":"^6.0.0","it-drain":"^2.0.0","it-foreach":"^1.0.0","it-map":"^2.0.0","it-pipe":"^2.0.2","it-pushable":"^3.0.0","it-reader":"^6.0.1","p-defer":"^4.0.0","random-int":"^3.0.0","varint":"^6.0.0"},"gitHead":"fca82b7704de432bd55bd4002403d24471bca94f","_id":"it-length-prefixed@8.0.4","_nodeVersion":"18.12.1","_npmVersion":"8.19.3","dist":{"integrity":"sha512-5OJ1lxH+IaqJB7lxe8IAIwt9UfSfsmjKJoAI/RO9djYoBDt1Jfy9PeVHUmOfqhqyu/4kJvWBFAJUaG1HhLQ12A==","shasum":"80bd356d93d77a8989a71200f8ca0860db040404","tarball":"http://registry-npm.ywwl.com/it-length-prefixed/download/it-length-prefixed-8.0.4.tgz","fileCount":25,"unpackedSize":46374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHBRk1Mf5Xbkvrtk0JoRWmEM/xJvHnzh4rW/fIiNEyBnAiEAu64dldCIXZhX4SgP8aiHXapQ3JoH/XNVZH/KC09tQzw="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjpFnMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrYexAAiPVIHr7gU3V3bnBs6PevBNtb5FCcznc0ym601tFolQJhOh+X\r\nli3Czm4y03TlDajO6T3fh+bpqKgKaDVIqqIUbF2F9m8MI8H0u30RqcZQGavu\r\nc4SzUWIlFDz40Z1dYNQm4mjH+9KmuxzQdpq+EOqgvIh1qpzdTmuULmPKna1w\r\nfcwtUmmV2qxgNCGrI1ZgcDhIhU4+ZoKdIt1zCnyR3N9ZvoPjTgsjP/3PlB/h\r\n1GGjljqXDTmNEO1DXisSzYajbv/2iku7QYh0NIA1zZQ0GRYqyF1wbil2JjcH\r\nBPG0i5gHjxeWmZROhn8QRfpGrGrJu4zYSa5HCROjGSC4fD8B7dzNk0xCK2x3\r\n8oBdwJMOK3QQRVFKhhtmQVHVYAKxX1QI3VMySzF5kK1i81dwQdxGxmK8B7Lu\r\nKekCKpFv8GQwETYbgVDsyFQaSWtKqu3aEmckBvE3eNn/yfSZj1zouf6CINmD\r\nQbYg4N4DpQ07ooXc0TJLRozZQ7zwTvQEv6I3Vew7hgHwYy10aOxrNDPbWCFc\r\nI4i2FWThe8pona6la9P7qrVpZATbA08U1x2SQ7V4cf8LEo3GguyzREQ/+2OI\r\nedIkLOf0sv8krS3QSh5sw/iJt0L0Erq+7DGUi1mqc9J8yIT414QaB2g+Gm4G\r\n/OaXUdletC+Zuep7KR9iGTHu4S5u1TvC9yA=\r\n=3rkw\r\n-----END PGP SIGNATURE-----\r\n","size":12874,"noattachment":false,"key":"/it-length-prefixed/-/it-length-prefixed-8.0.4.tgz"},"_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"},{"name":"alanshaw","email":"alan138@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/it-length-prefixed_8.0.4_1671715276465_0.4489578859844596"},"_hasShrinkwrap":false,"readme":"# it-length-prefixed <!-- omit in toc -->\n\n[![codecov](https://img.shields.io/codecov/c/github/alanshaw/it-length-prefixed.svg?style=flat-square)](https://codecov.io/gh/alanshaw/it-length-prefixed)\n[![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)\n\n> Streaming length prefixed buffers with async iterables\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [API](#api)\n  - [`encode(source, [opts])`](#encodesource-opts)\n  - [`encode.single(chunk, [opts])`](#encodesinglechunk-opts)\n  - [`decode(source, [opts])`](#decodesource-opts)\n  - [`decode.fromReader(reader, [opts])`](#decodefromreaderreader-opts)\n- [Contribute](#contribute)\n- [API Docs](#api-docs)\n- [License](#license)\n- [Contribution](#contribution)\n\n## Install\n\n```console\n$ npm i it-length-prefixed\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `ItLengthPrefixed` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/it-length-prefixed/dist/index.min.js\"></script>\n```\n\n## Usage\n\n```js\nimport { pipe } from 'it-pipe'\nimport * as lp from 'it-length-prefixed'\n\nconst encoded = []\n\n// encode\nawait pipe(\n  [uint8ArrayFromString('hello world')],\n  (source) => lp.encode(source),\n  async source => {\n    for await (const chunk of source) {\n      encoded.push(chunk.slice()) // (.slice converts Uint8ArrayList to Uint8Array)\n    }\n  }\n)\n\nconsole.log(encoded)\n// => [Buffer <0b 68 65 6c 6c 6f 20 77 6f 72 6c 64>]\n\nconst decoded = []\n\n// decode\nawait pipe(\n  encoded, // e.g. from above\n  (source) => lp.decode(source),\n  async source => {\n    for await (const chunk of source) {\n      decoded.push(chunk.slice()) // (.slice converts Uint8ArrayList to Uint8Array)\n    }\n  }\n)\n\nconsole.log(decoded)\n// => [Buffer <68 65 6c 6c 6f 20 77 6f 72 6c 64>]\n```\n\n## API\n\n```js\nimport {\n  encode, decode\n} from 'it-length-prefixed'\n\nimport {\n  encode\n} from 'it-length-prefixed/encode'\n\nimport {\n  decode,\n  MAX_LENGTH_LENGTH,\n  MAX_DATA_LENGTH\n} from 'it-length-prefixed/decode'\n```\n\n### `encode(source, [opts])`\n\n- `source: Iterable<Uint8ArrayList | Uint8Array> | AsyncIterable<Uint8ArrayList | Uint8Array>` source to read bytes from\n- `opts: Object`, optional\n  - `lengthEncoder: Function`: A function that encodes the length that will prefix each message. By default this is a [`varint`](https://www.npmjs.com/package/varint) encoder. It is passed a `value` to encode, an (optional) `target` buffer to write to and an (optional) `offset` to start writing from. The function should encode the `value` into the `target` (or alloc a new Buffer if not specified), set the `lengthEncoder.bytes` value (the number of bytes written) and return the `target`.\n\nReturns `Generator` or `AsyncGenerator` that yields [`Uint8ArrayList`](https://www.npmjs.com/package/uint8arraylist) objects. All messages will be prefixed with a length, determined by the `lengthEncoder` function.\n\n### `encode.single(chunk, [opts])`\n\n- `chunk: Buffer|Uint8ArrayList` chunk to encode\n- `opts: Object`, optional\n  - `lengthEncoder: Function`: See description above. Note that this encoder will *not* be passed a `target` or `offset` and so will need to allocate a buffer to write to.\n\nReturns a `Uint8ArrayList` containing the encoded chunk.\n\n### `decode(source, [opts])`\n\n- `source: Iterable<Uint8ArrayList | Uint8Array> | AsyncIterable<Uint8ArrayList | Uint8Array>` source to read bytes from\n- `opts: Object`, optional\n  - `maxLengthLength`: If provided, will not decode messages whose length section exceeds the size specified, if omitted will use the default of 147 bytes.\n  - `maxDataLength`: If provided, will not decode messages whose data section exceeds the size specified, if omitted will use the default of 4MB.\n  - `onLength(len: Number)`: Called for every length prefix that is decoded from the stream\n  - `onData(data: Uint8ArrayList)`: Called for every chunk of data that is decoded from the stream\n  - `lengthDecoder: Function`: A function that decodes the length that prefixes each message. By default this is a [`varint`](https://www.npmjs.com/package/varint) decoder. It is passed some `data` to decode which is a [`Uint8ArrayList`](https://www.npmjs.com/package/uint8arraylist). The function should decode the length, set the `lengthDecoder.bytes` value (the number of bytes read) and return the length. If the length cannot be decoded, the function should throw a `RangeError`.\n\nReturns `Generator` or `AsyncGenerator` that yields [`Uint8ArrayList`](https://www.npmjs.com/package/uint8arraylist) objects.\n\n### `decode.fromReader(reader, [opts])`\n\nBehaves like `decode` except it only reads the exact number of bytes needed for each message in `reader`.\n\n- `reader: Reader`: An [it-reader](https://github.com/alanshaw/it-reader)\n- `opts: Object`, optional\n  - `maxLengthLength`: If provided, will not decode messages whose length section exceeds the size specified, if omitted will use the default of 147 bytes.\n  - `maxDataLength`: If provided, will not decode messages whose data section exceeds the size specified, if omitted will use the default of 4MB.\n  - `onData(data: Uint8ArrayList)`: Called for every chunk of data that is decoded from the stream\n  - `lengthEncoder: Function`: See description above.\n\nReturns `Generator` or `AsyncGenerator` that yields [`Uint8ArrayList`](https://www.npmjs.com/package/uint8arraylist) objects.\n\n## Contribute\n\nPRs and issues gladly accepted! Check out the [issues](https://github.com/alanshaw/it-length-prefixed/issues).\n\n## API Docs\n\n- <https://alanshaw.github.io/it-length-prefixed>\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribution\n\nUnless 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.\n","publish_time":1671715276620,"_cnpm_publish_time":1671715276620,"dist-tags":{"latest":"11.0.1"}}