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

Method readableWebStream

lib/internal/fs/promises.js:328–391  ·  view source on GitHub ↗

* @typedef {import('../webstreams/readablestream').ReadableStream * } ReadableStream * @param {{ type?: 'bytes', autoClose?: boolean }} [options] * @returns {ReadableStream}

(options = kEmptyObject)

Source from the content-addressed store, hash-verified

326 * @returns {ReadableStream}
327 */
328 readableWebStream(options = kEmptyObject) {
329 if (this[kFd] === -1)
330 throw new ERR_INVALID_STATE('The FileHandle is closed');
331 if (this[kClosePromise])
332 throw new ERR_INVALID_STATE('The FileHandle is closing');
333 if (this[kLocked])
334 throw new ERR_INVALID_STATE('The FileHandle is locked');
335 this[kLocked] = true;
336
337 validateObject(options, 'options');
338 const {
339 type = 'bytes',
340 autoClose = false,
341 } = options;
342
343 validateBoolean(autoClose, 'options.autoClose');
344
345 if (type !== 'bytes') {
346 process.emitWarning(
347 'A non-"bytes" options.type has no effect. A byte-oriented steam is ' +
348 'always created.',
349 'ExperimentalWarning',
350 );
351 }
352
353 const readFn = FunctionPrototypeBind(this.read, this);
354 const ondone = async () => {
355 this[kUnref]();
356 if (autoClose) await this.close();
357 };
358
359 const ReadableStream = lazyReadableStream();
360 const readable = new ReadableStream({
361 type: 'bytes',
362 autoAllocateChunkSize: 16384,
363
364 async pull(controller) {
365 const view = controller.byobRequest.view;
366 const { bytesRead } = await readFn(view, view.byteOffset, view.byteLength);
367
368 if (bytesRead === 0) {
369 controller.close();
370 await ondone();
371 }
372
373 controller.byobRequest.respond(bytesRead);
374 },
375
376 async cancel() {
377 await ondone();
378 },
379 });
380
381
382 const {
383 readableStreamCancel,
384 } = require('internal/webstreams/readablestream');
385 this[kRef]();

Callers 7

runFunction · 0.45
runWebStreamFunction · 0.45

Calls 4

lazyReadableStreamFunction · 0.85
readableStreamCancelFunction · 0.85
requireFunction · 0.50
onceMethod · 0.45

Tested by

no test coverage detected