Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/noop-stream
Create a readable Node.js stream that produces no data (or optionally blank data) or a writable stream that discards data
https://github.com/sindresorhus/noop-stream
dev-null nodejs nodejs-stream noop npm-package readable-stream stream
Last synced: about 1 month ago
JSON representation
Create a readable Node.js stream that produces no data (or optionally blank data) or a writable stream that discards data
- Host: GitHub
- URL: https://github.com/sindresorhus/noop-stream
- Owner: sindresorhus
- License: mit
- Created: 2019-05-26T12:34:41.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-05-27T14:59:43.000Z (over 1 year ago)
- Last Synced: 2024-04-13T17:56:40.720Z (7 months ago)
- Topics: dev-null, nodejs, nodejs-stream, noop, npm-package, readable-stream, stream
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 53
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-cross-platform-nodejs - noop-stream - Cross-platform `fs.createReadStream('/dev/null')`. (Libraries / Streams)
README
# noop-stream
> Create a readable Node.js stream that produces no data (or optionally blank data) or a writable stream that discards data
This can be useful for testing, fixtures, draining a stream, etc. [(Example)](https://github.com/sindresorhus/file-type/commit/7d14761b757912bccc464fc3fb86398f2a533999)
It's like `fs.createReadStream('/dev/null')` but cross-platform.
## Install
```sh
npm install noop-stream
```## Usage
```js
import stream from 'node:stream';
import {readableNoopStream} from 'noop-stream';stream.pipeline(readableNoopStream({size: 10}), process.stdout);
``````js
import stream from 'node:stream';
import {writableNoopStream} from 'noop-stream';stream.pipeline(process.stdin, writableNoopStream());
```## API
### readableNoopStream(options?)
Create a readable Node.js stream that produces no data (or optionally blank data).
Options are passed to the [`stream.Readable` constructor](https://nodejs.org/api/stream.html#stream_new_stream_readable_options), except for the `read` option.
You can also specify a `size` option, which is the size in bytes to produce. By default, it's `0`. Set it to `Infinity` to make it produce data until you manually destroy the stream.
### writableNoopStream(options?)
Create a writable Node.js stream that discards received data.
Options are passed to the [`stream.Writable` constructor](https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options), except for the `write` option.
## Related
- [dev-null-cli](https://github.com/sindresorhus/dev-null-cli) - Cross-platform `/dev/null`
- [random-bytes-readable-stream](https://github.com/sindresorhus/random-bytes-readable-stream) - Creates a readable stream producing cryptographically strong pseudo-random data