{"name":"it-length-prefixed","version":"3.0.1","description":"Streaming length prefixed buffers with async iterables","main":"src/index.js","scripts":{"test":"aegir test -t node -t browser","test:browser":"aegir test -t browser","test:node":"aegir test -t node","lint":"aegir lint","release":"aegir release -t node -t browser","release-minor":"aegir release --type minor -t node -t browser","release-major":"aegir release --type major -t node -t browser","build":"aegir build","coverage":"npx nyc --reporter=text --reporter=lcov npm run test:node -- --bail","coverage-publish":"npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov"},"repository":{"type":"git","url":"git+https://github.com/alanshaw/it-length-prefixed.git"},"keywords":["varint","async","iterable","iterator","length-prefixed-stream","length-prefixed"],"author":{"name":"Alan Shaw"},"license":"MIT","bugs":{"url":"https://github.com/alanshaw/it-length-prefixed/issues"},"homepage":"https://github.com/alanshaw/it-length-prefixed#readme","dependencies":{"bl":"^4.0.2","buffer":"^5.5.0","varint":"^5.0.0"},"devDependencies":{"aegir":"^21.4.0","chai":"^4.2.0","iso-random-stream":"^1.1.1","it-block":"^2.0.0","it-pipe":"^1.1.0","it-pushable":"^1.4.0","it-reader":"^2.1.0","p-defer":"^3.0.0","random-int":"^2.0.0","streaming-iterables":"^4.1.2"},"contributors":[{"name":"Friedel Ziegelmayer","email":"dignifiedquire@gmail.com"},{"name":"Alan Shaw","email":"alan.shaw@protocol.ai"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Maciej Krüger","email":"mkg20001@gmail.com"},{"name":"Projjol Banerji","email":"probaner23@gmail.com"},{"name":"Richard Littauer","email":"richard.littauer@gmail.com"},{"name":"Hugo Dias","email":"mail@hugodias.me"},{"name":"Dmitriy Ryajov","email":"dryajov@gmail.com"}],"gitHead":"a3b8f0d5a1b7ddcfdc66819f3e456d7d46444f2d","_id":"it-length-prefixed@3.0.1","_nodeVersion":"13.9.0","_npmVersion":"6.13.7","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"dist":{"integrity":"sha512-QnfnFkpklDhWpyPQ2al6pdqmsQbwZAUpa7066e8S9RQxXo0s4o21ceqCG0n/0wdmvgfRSYsW5g2dYgchqtLZYw==","shasum":"8c4d829576f941eb17b94bc83ed0c3c78bf0a05a","tarball":"http://registry-npm.ywwl.com/it-length-prefixed/download/it-length-prefixed-3.0.1.tgz","fileCount":42,"unpackedSize":1934776,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJechtJCRA9TVsSAnZWagAAo98P/jZbBwSTJeYAQTS1QqGR\nHBcZaXlkyBhGLJNy1TqO0wdDrGhsHWDh81vFb2Fy93UW5QlaxIasSZ7pPdet\n3u6+VdcXhuTjbA6rvZR2MusPHJrgyQc8cvuoTzQRUK1eHdKARYUvK4hKqWgp\nPD0Jf0Cp5IC5bgxXekbSwbjVTxKEFkQdvzHsfhH+w/qPRnJti5B8pb+BKYVy\n/Ra/oX8wKR8Afg+qKQyjNwXnkZO+ij3ox+axJzdaom3TIWczo8i0RXHY1/YD\nC3JdXdif5GsxxMJlUYbrdyOoeeWnRBIsNatPs3Td49ujZ5Ddcjnfvc+W3Kgu\nV7khLfz7ZC0d+tyvLcChtvpzht4evJYHeuycq/ZrZ4rN+CBCGDH8eARMc1JM\n14HOPxadKYyVqI4meWU64hkbSTmMh7NHLou/76cS2+i6pTVRz0BZcgwVgDNn\nVmu3gNBvMkYXtzGL4flRZ0X5OtO03B8kGpHvTAHbK1VR0Nhd4CVfs45F5dko\n5UWQrnBVcPniJDoP31YWx0PivugJBItoP9+HSuHIKnsJVQKwsOgiiVJaMPww\nSs+qDWHbuRCvAvTHBGXuwGg0ojAKuPNJJXMvGNV9WYRnwjh7e/N8F9KglIpN\ncsdh/0x02x/re7+68GXwHwDoaAbQUDTm7vBstnG6i5eQeQQ+h31HUD7Nwfc3\nUjCL\r\n=LqgP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBFwRb680wk3tfjHWD0rWzLas8tFi3J5iU4QBB9ELjBpAiAQOuFOokUMLZcA03xQ+PTIFjyYIOQJojo4hne+kkk8LQ=="}],"size":1310805,"noattachment":false,"key":"/it-length-prefixed/-/it-length-prefixed-3.0.1.tgz"},"maintainers":[{"name":"alanshaw","email":"alan138@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/it-length-prefixed_3.0.1_1584536392628_0.7546130377139286"},"_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":1584536392754,"_cnpm_publish_time":1584536392754,"dist-tags":{"latest":"11.0.1"}}