{"name":"slice-source","version":"0.1.1","description":"A readable stream reader that reads a desired number of bytes.","keywords":["binary","stream","reader"],"homepage":"https://github.com/mbostock/slice-source","license":"BSD-3-Clause","author":{"name":"Mike Bostock","url":"https://bost.ocks.org/mike"},"main":"index.js","repository":{"type":"git","url":"git+ssh://git@github.com/mbostock/slice-source.git"},"scripts":{"pretest":"rm -rf build && mkdir build && rollup -f umd -n sources -o build/slice-source.js -- index.js","postpublish":"git push && git push --tags"},"devDependencies":{"rollup":"0.34"},"gitHead":"6aba26720d64d2bd412d644467dfcbbcdf43b693","bugs":{"url":"https://github.com/mbostock/slice-source/issues"},"_id":"slice-source@0.1.1","_shasum":"ff82ac0e0fff76b3b355552cccbca863f8a522c9","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"mbostock","email":"mbostock@gmail.com"},"maintainers":[{"name":"mbostock","email":"mike@ocks.org"}],"dist":{"shasum":"ff82ac0e0fff76b3b355552cccbca863f8a522c9","tarball":"http://registry-npm.ywwl.com/slice-source/download/slice-source-0.1.1.tgz","integrity":"sha512-Y1gsXpAJcHFfOZcOyVtM7VS1X220HN6C4y5jhUl/eaiFph5zqWdd395XQM+B3r8uvCckd3piqbyN/+KVNAtxaQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHZoNXJ2Nxihot9nh9GxyZxgJKaisqcJ9o9sFYrK3NpBAiEAlXkAly7bYGD7SmWSxfWb3UC84J7jMEse7h3nGAd5S74="}],"size":3564,"noattachment":false,"key":"/slice-source/-/slice-source-0.1.1.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/slice-source-0.1.1.tgz_1473179635874_0.968729340704158"},"directories":{},"readme":"# slice-source\n\nA [readable stream reader](https://streams.spec.whatwg.org/#readable-stream-reader) that allows you to pull the specified number of bytes from the underlying readable stream. For example:\n\n```html\n<!DOCTYPE html>\n<script src=\"https://unpkg.com/slice-source@0\"></script>\n<script>\n\nfetch(\"https://cors-anywhere.herokuapp.com/\")\n  .then(response => {\n    return (function read(reader) {\n      return reader.slice(40).then(value => {\n        if (value == null) return;\n        console.log(value);\n        return read(reader);\n      });\n    })(sources.slice(response.body));\n  })\n  .catch(error => console.error(error.stack));\n\n</script>\n```\n\n## API Reference\n\n<a name=\"slice\" href=\"#slice\">#</a> <b>slice</b>(<i>stream</i>) [<>](https://github.com/mbostock/slice-source/blob/master/index.js#L4 \"Source\")\n<br><a href=\"#slice\">#</a> <b>slice</b>(<i>reader</i>)\n<br><a href=\"#slice\">#</a> <b>slice</b>(<i>source</i>)\n\nIf the specified *source* exposes a *source*.slice method, it is assumed to be a sliceable *source* and returned as-is. Otherwise, if the specified *reader* exposes a *reader*.read method, it is assumed to be a [readable stream *reader*](https://streams.spec.whatwg.org/#readable-stream-reader), and a new sliceable *source* for the specified *reader* is returned. Otherwise, the specified *reader* is assumed to be a [readable *stream*](https://streams.spec.whatwg.org/#rs), and a new sliceable *source* for the reader returned by *stream*.getReader is returned.\n\n<a name=\"source_slice\" href=\"#source_slice\">#</a> <i>source</i>.<b>slice</b>(<i>length</i>) [<>](https://github.com/mbostock/slice-source/blob/master/read.js \"Source\")\n\nReturns a Promise for the next chunk of data from the underlying stream, yielding a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) of *length* bytes, or the remaining bytes of the underlying stream if the underlying stream has more than zero but fewer than *length* bytes remaining, or null when no bytes remain in the stream.\n\n<a name=\"source_read\" href=\"#source_read\">#</a> <i>source</i>.<b>read</b>() [<>](https://github.com/mbostock/slice-source/blob/master/read.js \"Source\")\n\nReturns a Promise for the next chunk of data from the underlying stream. The yielded result is an object with the following properties:\n\n* `value` - a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), or undefined if the stream ended\n* `done` - a boolean which is true if the stream ended\n\n<a name=\"source_cancel\" href=\"#source_cancel\">#</a> <i>source</i>.<b>cancel</b>() [<>](https://github.com/mbostock/slice-source/blob/master/cancel.js \"Source\")\n\nReturns a Promise which is resolved when the underlying stream has been destroyed.\n","publish_time":1473179636101,"_cnpm_publish_time":1473179636101,"dist-tags":{"latest":"0.4.1"}}