https://github.com/meyfa/writable-wrapper
Node writable stream with a single data target
https://github.com/meyfa/writable-wrapper
node stream writable
Last synced: 5 months ago
JSON representation
Node writable stream with a single data target
- Host: GitHub
- URL: https://github.com/meyfa/writable-wrapper
- Owner: meyfa
- License: mit
- Created: 2018-05-03T11:06:59.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2026-01-13T16:11:11.000Z (5 months ago)
- Last Synced: 2026-01-13T18:35:40.268Z (5 months ago)
- Topics: node, stream, writable
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/writable-wrapper
- Size: 639 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# writable-wrapper
[](https://github.com/meyfa/writable-wrapper/actions/workflows/main.yml)
This TypeScript library for Node.js offers a writable stream implementation that
forwards all data to another `Writable`, the "target".
This is useful for adding functionality to a `Writable` without patching the
original object. `WritableWrapper` can be extended easily and will handle the
forwarding of any data written to it, while not making that data available to
any external consumer.
`Transform` streams are unsuitable for that purpose, since data listeners can
always be attached.
## Install
```
npm i writable-wrapper
```
## Usage
### Simple Example
```ts
import fs from 'fs'
import WritableWrapper from 'writable-wrapper'
const wrapper = new WritableWrapper(fs.createWriteStream('file.txt'))
```
### Custom Class Example
Of course, this functionality is really only useful for custom object types:
```ts
import fs from 'fs'
import WritableWrapper from 'writable-wrapper'
// Class for new items. You can write data, and when done, store the item.
// Not calling 'store' dismisses the item.
class NewlyCreatedItem extends WritableWrapper {
store (): void {
this.end(function () {
// store this item
})
}
}
// ...
const item = new NewlyCreatedItem(fs.createWriteStream('file.txt'))
item.write('hello world', 'utf8')
item.store()
```