{"id":17398225,"url":"https://github.com/codeman99/toflush","last_synced_at":"2025-03-27T22:16:18.142Z","repository":{"id":57377639,"uuid":"117316938","full_name":"CodeMan99/toflush","owner":"CodeMan99","description":"Node.js Streams - Transform on Flush","archived":false,"fork":false,"pushed_at":"2018-01-13T06:02:14.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T14:58:34.282Z","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":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeMan99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-13T05:27:44.000Z","updated_at":"2023-10-18T21:02:20.000Z","dependencies_parsed_at":"2022-09-26T16:41:53.665Z","dependency_job_id":null,"html_url":"https://github.com/CodeMan99/toflush","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Ftoflush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Ftoflush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Ftoflush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMan99%2Ftoflush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeMan99","download_url":"https://codeload.github.com/CodeMan99/toflush/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245931897,"owners_count":20695964,"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-10-16T14:42:27.846Z","updated_at":"2025-03-27T22:16:18.012Z","avatar_url":"https://github.com/CodeMan99.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# toflush [![Build Status](https://travis-ci.org/CodeMan99/toflush.svg?branch=master)](https://travis-ci.org/CodeMan99/toflush)\n\nTransform on Flush. Process an entire object mode stream in a single\nfunction call.\n\n## Install\n\n    npm install --save toflush\n\n## Usage\n\nMay have a synchronous callback.\n\n    fs.createReadStream('./rows.db') // newline delimited json\n      .pipe(split(JSON.parse))\n      .pipe(toflush(JSON.stringify))\n      .pipe(fs.createWriteStream('./database.json')) // write out as a JSON array\n\nMay have a asynchronous, Promise returning, callback.\n\n    fs.createReadStream('./images.db')\n      .pipe(split(JSON.parse))\n      .pipe(toflush(items =\u003e {\n        return fetch(items[0].url).then(response =\u003e {\n          if (response.ok) {\n            return response.buffer();\n          }\n\n          throw new Error(`${response.status} ${response.statusText}`);\n        });\n      }))\n      .on('error', error =\u003e /* handle fetch or response error */)\n      .pipe(fs.createWriteStream('./first.png'));\n\nThere are more examples available in the documentation and in the test cases.\n\n## API\n\nA single function that receives either an options object or a callback.\n\n### toflush(options) -\u003e stream.Transform\n\n * `options.callback` - function that receives all objects from the stream\n   as the first argument. Should return an object, array, or a promise. More\n   detail [below](#toflushcallback---streamtransform).\n * `options.name` - String name to use in error message. Default `toflush`. May\n   also be provide by the callback name.\n * `options.stream` - Boolean sanity flag that makes [vinyl][] content streams\n   opt-in.\n\n### toflush(callback) -\u003e stream.Transform\n\nSame as the callback in the options above. Any thrown error or rejection is\nemitted by the stream.\n\n * `callback(items) -\u003e Object` - take all objects, and return a single object.\n * `callback(items) -\u003e Object[]` - take all objects, and return any number of\n   objects. May be the same, more, or less than the input. Each item is pushed\n   into the stream, not the array.\n * `callback(items) -\u003e Promise\u003cObject\u003e` - take all objects, and _then_ promise\n   a single object.\n * `callback(items) -\u003e Promise\u003cObject[]\u003e` - take all objects, and _then_\n   promise any number of objects. May be the same, more, or less than the\n   input. Each item is pushed into the stream, not the array.\n\n## Required\n\nYou must be using node.js v4.x or later. This module has no dependencies,\ntaking advantage of the improved `stream.Transform` implementation.\n\n## Related\n\n * [vinyl][] - virtual file format, used heavily by `gulp`.\n * [get-stream][] - get stream as a string, buffer, or array.\n * [through2][] - older general stream utility. Heavily inspired this project.\n * [vinyl-map][] - vinyl specific tool, processing only file contents.\n\n## License\n\nMIT \u0026copy; Cody A. Taylor 2018\n\n[vinyl]: https://github.com/gulpjs/vinyl \"gulpjs/vinyl\"\n[get-stream]: https://github.com/sindresorhus/get-stream \"sindresorhus/get-stream\"\n[through2]: https://github.com/rvagg/through2 \"rvagg/through2\"\n[vinyl-map]: https://github.com/affirmix/vinyl-map \"affirmix/vinyl-map\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeman99%2Ftoflush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeman99%2Ftoflush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeman99%2Ftoflush/lists"}