@cjser/noop-stream 1.0.0-cjser.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/@cjser/noop-stream.tmp-26-1778153739280/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ readableNoopStream: () => readableNoopStream,
23
+ writableNoopStream: () => writableNoopStream
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_node_stream = require("node:stream");
27
+ var import_node_buffer = require("node:buffer");
28
+ function readableNoopStream({ size = 0, ...options } = {}) {
29
+ let producedSize = 0;
30
+ return new import_node_stream.Readable({
31
+ ...options,
32
+ read(readSize) {
33
+ let shouldEnd = false;
34
+ if (producedSize + readSize >= size) {
35
+ readSize = size - producedSize;
36
+ shouldEnd = true;
37
+ }
38
+ setImmediate(() => {
39
+ if (size === 0) {
40
+ this.push(null);
41
+ }
42
+ producedSize += readSize;
43
+ this.push(import_node_buffer.Buffer.alloc(readSize));
44
+ if (shouldEnd) {
45
+ this.push(null);
46
+ }
47
+ });
48
+ }
49
+ });
50
+ }
51
+ function writableNoopStream(options) {
52
+ return new import_node_stream.Writable({
53
+ ...options,
54
+ write(chunk, encding, callback) {
55
+ setImmediate(callback);
56
+ }
57
+ });
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ readableNoopStream,
62
+ writableNoopStream
63
+ });
package/index.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import {
2
+ ReadableOptions as ReadableNodeStreamOptions,
3
+ WritableOptions as WritableNodeStreamOptions,
4
+ } from 'node:stream';
5
+
6
+ export interface ReadableStreamOptions extends Omit<ReadableNodeStreamOptions, 'read'> {
7
+ /**
8
+ The amount of data to stream in bytes.
9
+
10
+ Set it to `Infinity` to make it produce data until you manually destroy the stream.
11
+
12
+ @default 0
13
+ */
14
+ readonly size?: number;
15
+ }
16
+
17
+ export interface WritableStreamOptions extends Omit<WritableNodeStreamOptions, 'write'> {}
18
+
19
+ /**
20
+ Create a readable Node.js stream that produces no data (or optionally blank data).
21
+
22
+ @example
23
+ ```
24
+ import stream from 'stream';
25
+ import {readableNoopStream} from '@cjser/noop-stream';
26
+
27
+ stream.pipeline(readableNoopStream({size: 10}), process.stdout);
28
+ ```
29
+ */
30
+ export function readableNoopStream(options?: ReadableStreamOptions): NodeJS.ReadableStream;
31
+
32
+ /**
33
+ Create a writable Node.js stream that discards received data.
34
+
35
+ @example
36
+ ```
37
+ import stream from 'stream';
38
+ import {writableNoopStream} from '@cjser/noop-stream';
39
+
40
+ stream.pipeline(process.stdin, writableNoopStream());
41
+ ```
42
+ */
43
+ export function writableNoopStream(options?: WritableStreamOptions): NodeJS.WritableStream;
package/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import {
2
+ Readable as ReadableStream,
3
+ Writable as WritableStream,
4
+ } from 'node:stream';
5
+ import {Buffer} from 'node:buffer';
6
+
7
+ export function readableNoopStream({size = 0, ...options} = {}) {
8
+ let producedSize = 0;
9
+
10
+ return new ReadableStream({
11
+ ...options,
12
+ read(readSize) {
13
+ let shouldEnd = false;
14
+
15
+ if ((producedSize + readSize) >= size) {
16
+ readSize = size - producedSize;
17
+ shouldEnd = true;
18
+ }
19
+
20
+ setImmediate(() => {
21
+ if (size === 0) {
22
+ this.push(null);
23
+ }
24
+
25
+ producedSize += readSize;
26
+ this.push(Buffer.alloc(readSize));
27
+
28
+ if (shouldEnd) {
29
+ this.push(null);
30
+ }
31
+ });
32
+ },
33
+ });
34
+ }
35
+
36
+ export function writableNoopStream(options) {
37
+ return new WritableStream({
38
+ ...options,
39
+ write(chunk, encding, callback) {
40
+ setImmediate(callback);
41
+ },
42
+ });
43
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@cjser/noop-stream",
3
+ "version": "1.0.0-cjser.2",
4
+ "description": "Create a readable Node.js stream that produces no data (or optionally blank data) or a writable stream that discards data",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "require": "./dist-cjser/index.cjs",
19
+ "default": "./index.js"
20
+ },
21
+ "engines": {
22
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
23
+ },
24
+ "scripts": {
25
+ "test": "xo && ava && tsd"
26
+ },
27
+ "files": [
28
+ "index.js",
29
+ "index.d.ts",
30
+ "dist-cjser"
31
+ ],
32
+ "keywords": [
33
+ "stream",
34
+ "readable",
35
+ "writable",
36
+ "readablestream",
37
+ "writablestream",
38
+ "noop",
39
+ "empty",
40
+ "dev",
41
+ "null",
42
+ "devnull",
43
+ "blank",
44
+ "drain",
45
+ "test",
46
+ "testing",
47
+ "fixture"
48
+ ],
49
+ "devDependencies": {
50
+ "@types/node": "^16.10.9",
51
+ "ava": "^3.15.0",
52
+ "get-stream": "^6.0.1",
53
+ "tsd": "^0.18.0",
54
+ "xo": "^0.45.0"
55
+ },
56
+ "main": "./dist-cjser/index.cjs",
57
+ "cjser": {
58
+ "sourceVersion": "1.0.0",
59
+ "cjserVersion": 2,
60
+ "original": {
61
+ "name": "noop-stream",
62
+ "version": "1.0.0",
63
+ "exports": "./index.js",
64
+ "repository": "sindresorhus/noop-stream",
65
+ "files": [
66
+ "index.js",
67
+ "index.d.ts"
68
+ ],
69
+ "scripts": {
70
+ "test": "xo && ava && tsd"
71
+ }
72
+ }
73
+ }
74
+ }
package/readme.md ADDED
@@ -0,0 +1,55 @@
1
+ # noop-stream
2
+
3
+ > Create a readable Node.js stream that produces no data (or optionally blank data) or a writable stream that discards data
4
+
5
+ This can be useful for testing, fixtures, draining a stream, etc. [(Example)](https://github.com/sindresorhus/file-type/commit/7d14761b757912bccc464fc3fb86398f2a533999)
6
+
7
+ It's like `fs.createReadStream('/dev/null')` but cross-platform.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install noop-stream
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import stream from 'stream';
19
+ import {readableNoopStream} from 'noop-stream';
20
+
21
+ stream.pipeline(readableNoopStream({size: 10}), process.stdout);
22
+ ```
23
+
24
+ ```js
25
+ import stream from 'stream';
26
+ import {writableNoopStream} from 'noop-stream';
27
+
28
+ stream.pipeline(process.stdin, writableNoopStream());
29
+ ```
30
+
31
+ ## API
32
+
33
+ ### readableNoopStream(options?)
34
+
35
+ Create a readable Node.js stream that produces no data (or optionally blank data).
36
+
37
+ Options are passed to the [`stream.Readable` constructor](https://nodejs.org/api/stream.html#stream_new_stream_readable_options), except for the `read` option.
38
+
39
+ 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.
40
+
41
+ ### writableNoopStream(options?)
42
+
43
+ Create a writable Node.js stream that discards received data.
44
+
45
+ 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.
46
+
47
+ ## Related
48
+
49
+ - [dev-null-cli](https://github.com/sindresorhus/dev-null-cli) - Cross-platform `/dev/null`
50
+ - [random-bytes-readable-stream](https://github.com/sindresorhus/random-bytes-readable-stream) - Creates a readable stream producing cryptographically strong pseudo-random data
51
+
52
+ ## cjser
53
+
54
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
55
+ Original repository: https://github.com/sindresorhus/noop-stream