| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6aa179b commit e2bf250
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const stream = require('stream'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const readable = new stream.Readable({ | ||
| 7 | + read: () => {}, | ||
| 8 | + encoding: 'utf16le', | ||
| 9 | + objectMode: true | ||
| 10 | + }); | ||
| 11 | + | ||
| 12 | + readable.push(Buffer.from('abc', 'utf16le')); | ||
| 13 | + readable.push(Buffer.from('def', 'utf16le')); | ||
| 14 | + readable.push(null); | ||
| 15 | + | ||
| 16 | + // Without object mode, these would be concatenated into a single chunk. | ||
| 17 | + assert.strictEqual(readable.read(), 'abc'); | ||
| 18 | + assert.strictEqual(readable.read(), 'def'); | ||
| 19 | + assert.strictEqual(readable.read(), null); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,51 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const stream = require('stream'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const readable = new stream.Readable({ | ||
| 7 | + read: () => {} | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + const writables = []; | ||
| 11 | + | ||
| 12 | + for (let i = 0; i < 5; i++) { | ||
| 13 | + const target = new stream.Writable({ | ||
| 14 | + write: common.mustCall((chunk, encoding, callback) => { | ||
| 15 | + target.output.push(chunk); | ||
| 16 | + callback(); | ||
| 17 | + }, 1) | ||
| 18 | + }); | ||
| 19 | + target.output = []; | ||
| 20 | + | ||
| 21 | + target.on('pipe', common.mustCall(() => {})); | ||
| 22 | + readable.pipe(target); | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + writables.push(target); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + const input = Buffer.from([1, 2, 3, 4, 5]); | ||
| 29 | + | ||
| 30 | + readable.push(input); | ||
| 31 | + | ||
| 32 | + // The pipe() calls will postpone emission of the 'resume' event using nextTick, | ||
| 33 | + // so no data will be available to the writable streams until then. | ||
| 34 | + process.nextTick(common.mustCall(() => { | ||
| 35 | + for (const target of writables) { | ||
| 36 | + assert.deepStrictEqual(target.output, [input]); | ||
| 37 | + | ||
| 38 | + target.on('unpipe', common.mustCall(() => {})); | ||
| 39 | + readable.unpipe(target); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + readable.push('something else'); // This does not get through. | ||
| 43 | + readable.push(null); | ||
| 44 | + readable.resume(); // Make sure the 'end' event gets emitted. | ||
| 45 | + })); | ||
| 46 | + | ||
| 47 | + readable.on('end', common.mustCall(() => { | ||
| 48 | + for (const target of writables) { | ||
| 49 | + assert.deepStrictEqual(target.output, [input]); | ||
| 50 | + } | ||
| 51 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const stream = require('stream'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const readable = new stream.Readable({ | ||
| 7 | + read: () => {} | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + assert.throws(() => readable.push([]), /Invalid non-string\/buffer chunk/); | ||
| 11 | + assert.throws(() => readable.push({}), /Invalid non-string\/buffer chunk/); | ||
| 12 | + assert.throws(() => readable.push(0), /Invalid non-string\/buffer chunk/); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const stream = require('stream'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const readable = new stream.Readable(); | ||
| 7 | + | ||
| 8 | + assert.throws(() => readable.read(), /not implemented/); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments