{"name":"it-length-prefixed","version":"3.0.0","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.0","buffer":"^5.4.3","varint":"^5.0.0"},"devDependencies":{"aegir":"^20.3.1","chai":"^4.2.0","it-block":"^2.0.0","it-pipe":"^1.1.0","it-pushable":"^1.4.0","it-reader":"^2.0.0","p-defer":"^3.0.0","random-bytes":"^1.0.0","random-int":"^2.0.0","streaming-iterables":"^4.1.0"},"contributors":[{"name":"Alan Shaw","email":"alan.shaw@protocol.ai"},{"name":"Dmitriy Ryajov","email":"dryajov@gmail.com"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Jacob Heun","email":"jake@andyet.net"},{"name":"Maciej Krüger","email":"mkg20001@gmail.com"},{"name":"Projjol Banerji","email":"probaner23@gmail.com"},{"name":"Richard Littauer","email":"richard.littauer@gmail.com"},{"name":"dignifiedquire","email":"dignifiedquire@users.noreply.github.com"},{"name":"dignifiedquire","email":"dignifiedquire@gmail.com"}],"gitHead":"063bf63d36a1aee901bf338c419f2950bc99abb9","_id":"it-length-prefixed@3.0.0","_nodeVersion":"12.11.0","_npmVersion":"6.11.3","_npmUser":{"name":"alanshaw","email":"alan138@gmail.com"},"dist":{"integrity":"sha512-OQPbWaGDcSK1Wzzi8XtyXscBV1sMhFz6q5zHGchBc5oV4hM6ifIl6PTS8stk8MqkBELSyWO6CbEluS1rg4UUTw==","shasum":"cdedb3a785796ba8263c97d9bd4816c9fe33a6d2","tarball":"http://registry-npm.ywwl.com/it-length-prefixed/download/it-length-prefixed-3.0.0.tgz","fileCount":42,"unpackedSize":1933978,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdzBr4CRA9TVsSAnZWagAAqEIP/RIvCJccuVlR9IQMuIzq\n2woXGsx1MaW7gLp1lw8uC2hNGJUbVRdJrfGub6gj+UhjBJlDyMFc4++Cyq9j\nNaI+pN1JsYT/kpmG14RppF1WXWrZxP3HSQwdXp/x0JsDpFKHg7qiSmcctz0r\nPombeMTtdBHtf1R9bS8ujQ5bGFCNFg8Cj373zZ6j9cpNWjgNxJr/S3QjT/Ub\ncsIYZ7t2LXA9wI2zIE/aawxa7CUzJQt2reqp667cQ6+xKPbkMK9jsN+KWpwQ\nsBsFJOKLBDO4fESzdx73QXzh7Xf6ZERHyaEncm89fuRGzgh4bC/luVSUB8xD\nRNhN5r2FiyWkifa+XykBlc0eZ/t0aFcBUnqG835zrPNG3zjQgNCeDAc9QMJ8\nGWeiAStnXLhPeKqt3J+RW9Se071wO1r8U1GMPqMzHc7KrL3Y4iBlSwgUesaY\nlyuTrSLgdgkI7w0xBcG73EFFysQz5QHfKeUz9yeUQlSVU+70zDf+gr3VYLV9\nwHLl4bVu/Hz73bvA9jnC6Oa02X6X5pYlFky99cRsDLCzUCODVJldEOSGvMTy\nJmD9rD4YKOXm8q//MpCoPPRDAXrEi2GZgoekHL4m2fezhQZabJekrilqPJSD\n/hsd9dJ2ch/VbsFmHhaKsNPnypj30Q+X3Dt7BDTPsYlpubhtrDdfK+edPuYx\novwR\r\n=d6N6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCqUGAUrrB6DM5/vPa/3KNezMxalQypcfolU/fehW+PJwIhAJ8s2p+ZVrjxOTJ6Nym35IkIbCnUN2WUoNDrzWVr99za"}],"size":1310540,"noattachment":false,"key":"/it-length-prefixed/-/it-length-prefixed-3.0.0.tgz"},"maintainers":[{"name":"alanshaw","email":"alan138@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/it-length-prefixed_3.0.0_1573657335643_0.41031949352243213"},"_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":1573657335904,"_cnpm_publish_time":1573657335904,"dist-tags":{"latest":"11.0.1"}}