MCPcopy Index your code
hub / github.com/nodejs/node / runWebStream

Function runWebStream

benchmark/fs/bench-filehandle-pull-vs-webstream.js:120–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118}
119
120async function runWebStream() {
121 const fh = await fs.promises.open(filename, 'r');
122 try {
123 const rs = fh.readableWebStream();
124
125 const upper = new TransformStream({
126 transform(chunk, controller) {
127 const buf = new Uint8Array(chunk.length);
128 for (let i = 0; i < chunk.length; i++) {
129 const b = chunk[i];
130 buf[i] = (b >= 0x61 && b <= 0x7a) ? b - 0x20 : b;
131 }
132 controller.enqueue(buf);
133 },
134 });
135
136 const compress = new CompressionStream('gzip');
137 const output = rs.pipeThrough(upper).pipeThrough(compress);
138 const reader = output.getReader();
139
140 let totalBytes = 0;
141 while (true) {
142 const { done, value } = await reader.read();
143 if (done) break;
144 totalBytes += value.byteLength;
145 }
146 return totalBytes;
147 } finally {
148 await fh.close();
149 }
150}
151
152// ---------------------------------------------------------------------------
153// Pull/iter path: pull() with uppercase transform + selected compression

Callers 1

benchWebStreamFunction · 0.85

Calls 6

pipeThroughMethod · 0.80
getReaderMethod · 0.80
openMethod · 0.65
closeMethod · 0.65
readableWebStreamMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…