filehandle.readableWebStream()


    返回可用于读取文件数据的 ReadableStream

    Stability: 1 - Experimental

    Returns a ReadableStream that may be used to read the files data.

    An error will be thrown if this method is called more than once or is called after the FileHandle is closed or closing.

    import {
      open,
    } from 'node:fs/promises';
    
    const file = await open('./some/file/to/read');
    
    for await (const chunk of file.readableWebStream())
      console.log(chunk);
    
    await file.close();const {
      open,
    } = require('node:fs/promises');
    
    (async () => {
      const file = await open('./some/file/to/read');
    
      for await (const chunk of file.readableWebStream())
        console.log(chunk);
    
      await file.close();
    })();

    While the ReadableStream will read the file to completion, it will not close the FileHandle automatically. User code must still call the fileHandle.close() method.