{"id":13526592,"url":"https://github.com/spion/promise-streams","last_synced_at":"2025-12-15T18:57:14.802Z","repository":{"id":139149718,"uuid":"14903194","full_name":"spion/promise-streams","owner":"spion","description":"A collection of node.js streams that work well with promises (through, map, reduce, etc...)","archived":false,"fork":false,"pushed_at":"2018-06-18T15:45:15.000Z","size":38,"stargazers_count":94,"open_issues_count":10,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-02T06:21:55.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2013-12-03T19:16:34.000Z","updated_at":"2022-11-26T11:56:37.000Z","dependencies_parsed_at":"2024-01-07T00:08:24.944Z","dependency_job_id":null,"html_url":"https://github.com/spion/promise-streams","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spion%2Fpromise-streams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spion%2Fpromise-streams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spion%2Fpromise-streams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spion%2Fpromise-streams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spion","download_url":"https://codeload.github.com/spion/promise-streams/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222709889,"owners_count":17026764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:31.916Z","updated_at":"2025-12-15T18:57:14.723Z","avatar_url":"https://github.com/spion.png","language":"JavaScript","funding_links":[],"categories":["Repository","Modules"],"sub_categories":["Streams"],"readme":"# promise-streams\n\nA collection of streams that work well with promises (through, map, reduce)\n\n# example\n\nUsing ES6 arrow functions:\n\n```js\nvar Promise = require('bluebird'),\n    request = require('request'),\n    path = require('path'),\n    fs = require('fs'),\n    ps = require('promise-streams'),\n    select = require('./select-elements');\n\nPromise.promisifyAll(request);\n\nvar download = url =\u003e\n  ps.wait(request('http:' + url).pipe(\n    fs.createWriteStream(\n        'images/' + path.basename(url))));\n\nvar downloadAllFrom = url =\u003e\n    request(url)\n    .pipe(select('.post a img', el =\u003e el.attributes.SRC))\n    .pipe(ps.filter(url =\u003e /jpg$/.test(url.toLowerCase()))\n    .pipe(ps.map({concurrent: 4}, imgurl =\u003e download(imgurl, url)))\n    .reduce((count, stream) =\u003e count + 1, 0);\n\ndownloadAllFrom('http://imgur.com/').done(\n    total =\u003e console.log(total, \"images downloaded\"),\n    err   =\u003e console.error(err.stack))\n```\n\n\n# api\n\n#### ps.through\n\n`([opts:Options,] fn:(data[, enc]) =\u003e Promise)) =\u003e PromiseStream`\n\nCreate a through-promise stream. Pass it a function that takes data and\nencoding and uses `this.push` to push values or promises. This function should\nreturn a promise that indicates when the object/chunk are fully processed.\n\nReturns a PromiseStream.\n\nOptions:\n\n  * `concurrent` - The maximum number of concurrent promises that are allowed.\n    When this limit is reached, the stream will stop processing data and will\n    start buffering incoming objects. Defaults to `1`\n\n  * `highWatermark` - the size (in objects) of the buffer mentioned above. When\n    this buffer fills up, the backpressure mechanism will activate. Its passed\n    to node's transform stream.\n\nThe other options are also passed to node's Transform stream constructor.\n\n#### ps.map\n\n`([opts:Options,] fn: (data[, enc]) =\u003e Promise) =\u003e MapPromiseStream`\n\nCreate a new MapPromiseStream. The function should return a promise for the\nnext object that will be pushed to the stream.\n\nOptions: Same as `ps.through`\n\n#### ps.filter\n\n`([opts:Options,] fn: (data[, enc]) =\u003e boolean) =\u003e FilterPromiseStream`\n\nCreate a new FilterPromiseStream. The function should return a boolean to\nindicate whether the data value should pass to the next stream\n\nOptions: Same as `ps.through`\n\n#### ps.reduce\n\n`([opts:Options,] fn: (acc, data[, enc]) =\u003e Promise) =\u003e ReducePromiseStream`\n\nReduces the objects in this promise stream. The function takes the resolved\ncurrent accumulator and data object and should return the next accumulator\nor a promise for the next accumulator.\n\nThe ReducePromiseStream has a `promise()` method which returns the final\naccumulator value\n\n```js\nprocess.stdin.pipe(split()).pipe(es.reduce(function(acc, el) {\n    return acc + el;\n})).promise().then(function(sum) {\n\n});\n```\n\n#### ps.wait\n\n`(s: Stream) =\u003e Promise`\n\nWait for the stream to end. Also captures errors.\n\n\n#### ps.collect\n\n`(s: Stream) =\u003e Promise\u003cBuffer | string\u003e`\n\nCollects data from a stream into a single buffer or string, depending on the encoding of the passed stream.\n\n#### ps.pipe\n\n`(source: Stream, destination: Stream) =\u003e Promise`\n\nPipes s1 to s2 and forwards all errors to the resulting promise. The promise is\nfulfilled without a value when the source stream ends.\n\n#### ps.pipeline\n\n`(source: Stream, ...streams: Stream[]) =\u003e Promise`\n\nLike pipe, but creates a pipeline of multiple streams.\n\n#### PromiseStream.prototype.push\n\nLike `this.push` in [through2](//github.com/rvagg/through2), but takes promise\narguments. It returns a promise that resolves when the pushed promise resolves,\nto make it possible to use `return this.push(data)`\n\n#### PromiseStream.prototype.map\n\n`([opts:Options,] fn: (data[, enc]) =\u003e Promise) =\u003e MapPromiseStream`\n\nCreate a new MapPromiseStream and pipes this promise stream to it.\n\n#### PromiseStream.prototype.filter\n\n`([opts:Options,] fn: (data[, enc]) =\u003e boolean) =\u003e FilterPromiseStream`\n\nCreate a new FilterPromiseStream and pipes this promise stream to it.\n\n#### PromiseStream.prototype.reduce\n\n`([opts:Options,] fn: (acc, data[, enc]) =\u003e Promise) =\u003e Promise`\n\nReduces the objects in this promise stream. The function takes the resolved\ncurrent accumulator and data object and should return the next accumulator\nor a promise for the next accumulator.\n\nReturns a promise for the final reduction result\n\n#### PromiseStream.promise\n\n`() =\u003e Promise`\n\nReturns a promise fulfilled at the end of the stream, rejected if any errors\nevents are emitted by the stream.\n\nFor ReducePromiseStreams, the promise is for the final reduction result. Any\nstream errors or exceptions encountered while reducing will result with a\nrejection of the promise.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspion%2Fpromise-streams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspion%2Fpromise-streams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspion%2Fpromise-streams/lists"}