{"_id":"promise-stream-reader","_rev":"2801903","name":"promise-stream-reader","description":"Consume Node.js readable streams using promises.","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"princjef","email":"princjef@gmail.com"}],"time":{"modified":"2022-08-05T03:14:05.000Z","created":"2018-04-28T18:21:59.397Z","1.0.1":"2018-04-28T19:29:13.682Z","1.0.0":"2018-04-28T18:21:59.397Z"},"users":{},"author":{"name":"Jeff Principe","email":"princjef@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/princjef/promise-stream-reader.git"},"versions":{"1.0.1":{"name":"promise-stream-reader","version":"1.0.1","description":"Consume Node.js readable streams using promises.","homepage":"https://github.com/princjef/promise-stream-reader#readme","repository":{"type":"git","url":"git+https://github.com/princjef/promise-stream-reader.git"},"bugs":{"url":"https://github.com/princjef/promise-stream-reader/issues"},"engines":{"node":">8.0.0"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"commit":"commit","commitmsg":"commitlint -e $GIT_PARAMS","lint":"tslint --project tsconfig.json --fix","clean":"rimraf dist","prebuild":"npm run clean && npm run lint","build":"tsc","watch":"tsc -w","pretest":"npm run build","test":"nyc ava dist/**/*.spec.js","pretest-nocover":"npm run build","test-nocover":"ava dist/**/*.spec.js","show-coverage":"opener ./coverage/index.html","coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","prerelease":"npm run build","release":"semantic-release"},"keywords":["promise","stream","readable","pipe"],"author":{"name":"Jeff Principe","email":"princjef@gmail.com"},"license":"MIT","devDependencies":{"@commitlint/cli":"^6.1.3","@commitlint/config-conventional":"^6.1.3","@commitlint/prompt-cli":"^6.1.3","@commitlint/travis-cli":"^6.1.3","@types/node":"^8.10.10","ava":"^0.25.0","codecov":"^3.0.1","husky":"^0.14.3","nyc":"^11.7.1","opener":"^1.4.3","rimraf":"^2.6.2","semantic-release":"^15.1.7","tslint":"^5.9.1","tslint-config-standard":"^7.0.0","typescript":"^2.8.3"},"nyc":{"sourceMap":true,"reporter":["text","html","json"],"include":["dist/**/*.js"],"exclude":["dist/**/*.spec.*","dist/**/*.d.ts","dist/**/*.map*"],"check-coverage":true,"lines":100,"statements":100,"functions":100,"branches":100,"watermarks":{"lines":[100,100],"statements":[100,100],"functions":[100,100],"branches":[100,100]}},"commitlint":{"extends":["@commitlint/config-conventional"]},"gitHead":"ebbc9c97b36699a493968665386cee4b1a870818","_id":"promise-stream-reader@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"princjef","email":"princjef@gmail.com"},"dist":{"shasum":"4e793a79c9d49a73ccd947c6da9c127f12923649","size":8309,"noattachment":false,"key":"/promise-stream-reader/-/promise-stream-reader-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/promise-stream-reader/download/promise-stream-reader-1.0.1.tgz"},"maintainers":[{"name":"princjef","email":"princjef@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/promise-stream-reader_1.0.1_1524943753477_0.2680099554789528"},"_cnpmcore_publish_time":"2021-12-22T23:52:32.196Z","publish_time":1524943753682,"_cnpm_publish_time":1524943753682},"1.0.0":{"name":"promise-stream-reader","version":"1.0.0","description":"Consume Node.js readable streams using promises.","homepage":"https://github.com/princjef/promise-stream-reader#readme","repository":{"type":"git","url":"git+https://github.com/princjef/promise-stream-reader.git"},"bugs":{"url":"https://github.com/princjef/promise-stream-reader/issues"},"engines":{"node":">8.0.0"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"commit":"commit","commitmsg":"commitlint -e $GIT_PARAMS","lint":"tslint --project tsconfig.json --fix","clean":"rimraf dist","prebuild":"npm run clean && npm run lint","build":"tsc","watch":"tsc -w","pretest":"npm run build","test":"nyc ava dist/**/*.spec.js","pretest-nocover":"npm run build","test-nocover":"ava dist/**/*.spec.js","show-coverage":"opener ./coverage/index.html","coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov"},"keywords":["promise","stream","readable","pipe"],"author":{"name":"Jeff Principe","email":"princjef@gmail.com"},"license":"MIT","devDependencies":{"@commitlint/cli":"^6.1.3","@commitlint/config-conventional":"^6.1.3","@commitlint/prompt-cli":"^6.1.3","@commitlint/travis-cli":"^6.1.3","@types/node":"^8.10.10","ava":"^0.25.0","codecov":"^3.0.1","husky":"^0.14.3","nyc":"^11.7.1","opener":"^1.4.3","rimraf":"^2.6.2","semantic-release":"^15.1.7","tslint":"^5.9.1","tslint-config-standard":"^7.0.0","typescript":"^2.8.3"},"nyc":{"sourceMap":true,"reporter":["text","html","json"],"include":["dist/**/*.js"],"exclude":["dist/**/*.spec.*","dist/**/*.d.ts","dist/**/*.map*"],"check-coverage":true,"lines":100,"statements":100,"functions":100,"branches":100,"watermarks":{"lines":[100,100],"statements":[100,100],"functions":[100,100],"branches":[100,100]}},"commitlint":{"extends":["@commitlint/config-conventional"]},"gitHead":"7c981880439849f9a32d84d9f88e0102ed3b3282","_id":"promise-stream-reader@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.1","_npmUser":{"name":"princjef","email":"princjef@gmail.com"},"dist":{"shasum":"e8418221a8ce0e98ad865ae768d8f7d87243498b","size":5254,"noattachment":false,"key":"/promise-stream-reader/-/promise-stream-reader-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/promise-stream-reader/download/promise-stream-reader-1.0.0.tgz"},"maintainers":[{"name":"princjef","email":"princjef@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/promise-stream-reader_1.0.0_1524939719297_0.6828782542622234"},"_cnpmcore_publish_time":"2021-12-22T23:52:32.095Z","publish_time":1524939719397,"_cnpm_publish_time":1524939719397}},"readme":"# promise-stream-reader\n\n[![Travis CI build status](https://travis-ci.org/princjef/promise-stream-reader.svg?branch=dev)](https://travis-ci.org/princjef/promise-stream-reader)\n[![codecov](https://codecov.io/gh/princjef/promise-stream-reader/branch/dev/graph/badge.svg)](https://codecov.io/gh/princjef/promise-stream-reader)\n[![npm version](https://img.shields.io/npm/v/promise-stream-reader.svg)](https://npmjs.org/package/promise-stream-reader)\n\n\nConsume data from Node.js readable streams using promises and async/await to\ncontrol flow.\n\n```\nnpm install promise-stream-reader\n```\n\n## Usage\n\nThe base export is a function that returns a writable stream to which you can\npipe your readable/duplex stream.\n\n```js\nconst promiseStream = require('promise-stream-reader');\n\nasync function readStream(readableStream) {\n    const reader = promiseStream();\n    readableStream.pipe(reader);\n\n    // Read 4 bytes of data from the stream\n    const part1 = await reader.read(4);\n\n    // Skip 10 bytes of data\n    await reader.skip(10);\n\n    // You can also have multiple read/skip calls pending at the same time. They\n    // will be filled with data in the order they were initially requested.\n    const [part2, part3] = await Promise.all([\n        reader.read(6),\n        reader.read(8)\n    ]);\n\n    // When you're all done, you can close up the streams\n    readableStream.unpipe(reader);\n    reader.destroy();\n    readableStream.destroy();\n}\n\nreadStream(/* some readable stream */)\n    .catch(err => { /* don't forget to handle rejected promises */ });\n```\n\n*NOTE: If you're using Typescript, the base exported function is available under\nthe default export.*\n\n## Why?\n\nThere are [two modes][stream two modes] for reading data from a readable stream\nin Node.js, but each has limitations that can be frustrating for a final\nconsumer:\n\n * [`on('data')`][stream data event] (flowing) allows you to deal with data as\n   it comes in, but you have to take care of packaging the data up into the\n   chunks appropriate for your use case. You will also continue to receive data\n   as fast as it comes in by default, even if you're not really ready for it.\n\n * [`read()`][stream read] (paused) allows you to explicitly request data but\n   has no mechanism for asynchronous retrieval. As a result, it will return null\n   if there is no data available yet, forcing you to poll until you get the data\n   you want. You can combine this with listening to the `'readable'` event, but\n   then you're using two patterns and still have to wrap it if you want to use\n   promises.\n\nThis solution aims to strike a balance between the two, allowing you to request\nthe data you want when you need it and have the stream provide it to you as soon\nas it's available. You get to process the data quickly without extra\nmanipulation or control flow required and can proceed at your own pace.\n\n## Contributing\n\nWant to contribute to the project? Go check out the [Contribution Guide](CONTRIBUTING.md) for instructions to set up your development environment, open\nan issue and create a pull request.\n\n[stream two modes]: https://nodejs.org/api/stream.html#stream_two_modes\n[stream read]: https://nodejs.org/api/stream.html#stream_readable_read_size\n[stream data event]: https://nodejs.org/api/stream.html#stream_event_data","_attachments":{},"homepage":"https://github.com/princjef/promise-stream-reader#readme","bugs":{"url":"https://github.com/princjef/promise-stream-reader/issues"},"license":"MIT"}