GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: return stream/iter from() results unchanged from from() · nodejs/node@1f791c9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • stream_iter.md
  • lib/internal/streams/iter
    • from.js
  • test/parallel
    • test-stream-iter-from-async.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/stream_iter.md‎

Copy file name to clipboardExpand all lines: doc/api/stream_iter.md
+3-3Lines changed: 3 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ Objects implementing `Symbol.for('Stream.toAsyncStreamable')` or
602602
precedence over the iteration protocols (`Symbol.asyncIterator`,
603603
`Symbol.iterator`).
604604

605-
The readable of a [`push()`][] stream without transforms and the iterables
606-
returned by [`fromReadable()`][] already yield normalized batches, so `from()`
607-
returns them unchanged.
605+
The readable of a [`push()`][] stream without transforms, the iterables
606+
returned by [`fromReadable()`][], and the results of `from()` itself already
607+
yield normalized batches, so `from()` returns them unchanged.
608608

609609
```mjs
610610
import { Buffer } from 'node:buffer';
Collapse file

‎lib/internal/streams/iter/from.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/from.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function createNormalizationIterator(createIterator) {
180180
[SymbolAsyncIterator]() {
181181
return this;
182182
},
183+
[kValidatedSource]: true,
183184
}, null);
184185
}
185186
if (iterator[kNextSyncBatch] !== undefined) {
@@ -202,6 +203,7 @@ function createNormalizationIterator(createIterator) {
202203
[SymbolAsyncIterator]() {
203204
return this;
204205
},
206+
[kValidatedSource]: true,
205207
}, null);
206208
}
207209
return ObjectSetPrototypeOf({
@@ -220,6 +222,7 @@ function createNormalizationIterator(createIterator) {
220222
[SymbolAsyncIterator]() {
221223
return this;
222224
},
225+
[kValidatedSource]: true,
223226
}, null);
224227
}
225228

@@ -229,6 +232,7 @@ function createNormalizationSource(createIterator) {
229232
[SymbolAsyncIterator]() {
230233
return createNormalizationIterator(createIterator);
231234
},
235+
[kValidatedSource]: true,
232236
};
233237
}
234238

@@ -1349,6 +1353,7 @@ function from(input) {
13491353
async *[SymbolAsyncIterator]() {
13501354
yield [chunk];
13511355
},
1356+
[kValidatedSource]: true,
13521357
};
13531358
}
13541359

@@ -1392,6 +1397,7 @@ function from(input) {
13921397
async *[SymbolAsyncIterator]() {
13931398
// Empty - yield nothing
13941399
},
1400+
[kValidatedSource]: true,
13951401
};
13961402
}
13971403
if (isUint8Array(input[0])) {
@@ -1409,6 +1415,7 @@ function from(input) {
14091415
}
14101416
}
14111417
},
1418+
[kValidatedSource]: true,
14121419
};
14131420
}
14141421
}
Collapse file

‎test/parallel/test-stream-iter-from-async.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-from-async.js
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,35 @@ async function testFromSyncSourceQueuesBehindReturn() {
801801
]);
802802
}
803803

804+
// from() returns its own results unchanged: they already yield normalized
805+
// batches, and normalizing them again would add a layer to every read.
806+
async function testFromReturnsItsOwnResults() {
807+
async function* asyncSource() {
808+
yield 'a';
809+
yield [new Uint8Array([98])];
810+
}
811+
812+
function* syncSource() {
813+
yield 'c';
814+
yield new Uint8Array([100]);
815+
}
816+
const inputs = [
817+
[asyncSource(), 'ab'],
818+
[syncSource(), 'cd'],
819+
['ef', 'ef'],
820+
[[new Uint8Array([103]), new Uint8Array([104])], 'gh'],
821+
[[], ''],
822+
[{ [Symbol.for('Stream.toAsyncStreamable')]() { return 'ij'; } }, 'ij'],
823+
];
824+
for (const [input, expected] of inputs) {
825+
const normalized = from(input);
826+
assert.strictEqual(from(normalized), normalized);
827+
assert.strictEqual(await text(from(from(normalized))), expected);
828+
}
829+
}
830+
804831
Promise.all([
832+
testFromReturnsItsOwnResults(),
805833
testFromString(),
806834
testFromAsyncGenerator(),
807835
testFromAsyncIteratorResultShapes(),

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.