{"id":17859309,"url":"https://github.com/dex4er/js-promise-writable","last_synced_at":"2025-10-17T00:13:11.767Z","repository":{"id":39104101,"uuid":"84569499","full_name":"dex4er/js-promise-writable","owner":"dex4er","description":"Return promise for writable stream","archived":false,"fork":false,"pushed_at":"2025-03-17T03:43:55.000Z","size":138,"stargazers_count":5,"open_issues_count":9,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T04:32:40.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/promise-writable","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dex4er.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-10T14:43:52.000Z","updated_at":"2024-06-21T11:11:33.000Z","dependencies_parsed_at":"2023-09-25T22:18:03.088Z","dependency_job_id":"ae4a9cce-57be-4629-bc09-220fcb943723","html_url":"https://github.com/dex4er/js-promise-writable","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dex4er%2Fjs-promise-writable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dex4er%2Fjs-promise-writable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dex4er%2Fjs-promise-writable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dex4er%2Fjs-promise-writable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dex4er","download_url":"https://codeload.github.com/dex4er/js-promise-writable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244079687,"owners_count":20394779,"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-28T06:42:20.034Z","updated_at":"2025-10-17T00:13:11.700Z","avatar_url":"https://github.com/dex4er.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# promise-writable\n\n\u003c!-- markdownlint-disable MD013 --\u003e\n\n[![GitHub](https://img.shields.io/github/v/release/dex4er/js-promise-writable?display_name=tag\u0026sort=semver)](https://github.com/dex4er/js-promise-writable)\n[![CI](https://github.com/dex4er/js-promise-writable/actions/workflows/ci.yaml/badge.svg)](https://github.com/dex4er/js-promise-writable/actions/workflows/ci.yaml)\n[![Trunk Check](https://github.com/dex4er/js-promise-writable/actions/workflows/trunk.yaml/badge.svg)](https://github.com/dex4er/js-promise-writable/actions/workflows/trunk.yaml)\n[![Coverage Status](https://coveralls.io/repos/github/dex4er/js-promise-writable/badge.svg)](https://coveralls.io/github/dex4er/js-promise-writable)\n[![npm](https://img.shields.io/npm/v/promise-writable.svg)](https://www.npmjs.com/package/promise-writable)\n\n\u003c!-- markdownlint-enable MD013 --\u003e\n\nThis module allows conversion `Writable` stream into its promisified version,\nwhich returns\n[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\nobject fulfilled when [`open`](https://nodejs.org/api/fs.html#fs_event_open),\n[`close`](https://nodejs.org/api/fs.html#fs_event_close),\n[`pipe`](https://nodejs.org/api/stream.html#stream_event_pipe),\n[`unpipe`](https://nodejs.org/api/stream.html#stream_event_unpipe),\n[`finish`](https://nodejs.org/api/stream.html#stream_event_finish) or\n[`error`](https://nodejs.org/api/stream.html#stream_event_error) events\noccurred.\n\n## Requirements\n\nThis module requires Node \u003e= 16.\n\n## Installation\n\n```shell\nnpm install promise-writable\n```\n\n_Additionally for Typescript:_\n\n```shell\nnpm install -D @types/node\n```\n\n## Usage\n\n```js\nimport PromiseWritable from \"promise-writable\"\n```\n\n### constructor\n\n```js\nconst promiseWritable = new PromiseWritable(stream)\n```\n\n`PromiseWritable` object requires `Writable` object to work.\n\n_Example:_\n\n```js\nimport PromiseWritable from \"promise-writable\"\nimport fs from \"node:fs\"\n\nconst stream = fs.createWriteStream(\"/tmp/test.txt\")\nconst promiseWritable = new PromiseWritable(stream)\n```\n\n### stream\n\n```js\nconst stream = promiseWritable.stream\n```\n\nOriginal stream object.\n\n_Example:_\n\n```js\nconsole.log(promiseWritable.stream.flags)\n```\n\n### write\n\n```js\nconst written = await promiseWritable.write(chunk)\n```\n\nThis method returns `Promise` which is fulfilled when the stream accepted a\nchunk (`write` method returned that stream is still writable or `drain` event\noccured) or stream is ended (`finish` event).\n\nPromise resolves to number that counts written bytes.\n\n_Example:_\n\n```js\nconst written = await promiseWritable.write(new Buffer(\"foo\"))\n```\n\n### writeAll\n\n```js\nconst total = await promiseWritable.writeAll(content, chunkSize)\n```\n\nThis method returns `Promise` which is fulfilled when the stream accepts\ncontent. This method writes the content chunk by chunk. The default chunk\nsize is 64 KiB.\n\nPromise resolves to a number that counts written bytes.\n\n_Example:_\n\n```js\nconst total = await promiseWritable.writeAll(new Buffer(\"foobarbaz\"), 3)\n```\n\n### once\n\n```js\nawait promiseWritable.once(event)\n```\n\nThis method returns `Promise` which is fulfilled when stream emits `event`. The\nresult of this event is returned.\n\nPromise resolves to `undefined` value if the stream is already closed or\ndestroyed.\n\n_Example:_\n\n```js\nconst fd = await promiseWritable.once(\"open\")\nprocess.stdin(promiseWritable.stream)\n\nawait promiseWritable.once(\"close\")\n\nconst promise = promiseWritable.once(\"pipe\")\nprocess.stdin.pipe(promiseWritable.stream)\nconst src = await promise\n\nconst promise = promiseWritable.once(\"unpipe\")\nprocess.stdin.unpipe(promiseWritable.stream)\nconst src = await promise\n```\n\n### end\n\n```js\nawait promiseWritable.end()\n```\n\nThis method ends the stream and returns `Promise` which is fulfilled when stream\nis finished. No value is returned.\n\n### destroy\n\n```js\npromiseWritable = promiseWritable.destroy()\n```\n\nThis method calls `destroy` method on stream and cleans up all own handlers.\n\nThe method returns this object.\n\n## See also\n\n[`PromiseReadable`](https://www.npmjs.com/package/promise-readable),\n[`PromiseDuplex`](https://www.npmjs.com/package/promise-duplex),\n[`PromiseSocket`](https://www.npmjs.com/package/promise-socket),\n[`PromisePiping`](https://www.npmjs.com/package/promise-piping).\n\n## License\n\nCopyright (c) 2017-2024 Piotr Roszatycki \u003cmailto:piotr.roszatycki@gmail.com\u003e\n\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdex4er%2Fjs-promise-writable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdex4er%2Fjs-promise-writable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdex4er%2Fjs-promise-writable/lists"}