Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options for FileHandle.readableWebStream() #40606

Closed
jimmywarting opened this issue Oct 26, 2021 · 4 comments
Closed

options for FileHandle.readableWebStream() #40606

jimmywarting opened this issue Oct 26, 2021 · 4 comments
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. stale

Comments

@jimmywarting
Copy link

Is your feature request related to a problem? Please describe.
I have just found out that a FileHandle got a readableWebStream function. I wish to use it on fetch-blob but i can't. I need to be able to slice a file and read from a different start/end position, much like

const file = fileFromSync('./readme.md')
const readbleWebStream = file.slice(1, 2).stream()

Describe the solution you'd like
Similar to fs.createReadableStream(fd, options) you also have options to start and stop. this is what i'm currently using. It would be useful if readableWebStream got them as well. for now i will have to resort to using stream.Readable.toWeb(streamReadable) instead...

Describe alternatives you've considered
I wish we got a #39015 and #37340 implemented into core natively. This is the only two blocker we have from ditching fetch-blob. only using Buffer.Blob dose not work for us since we need to handle large files and big FormData payloads that dose not live in memory

@VoltrexKeyva VoltrexKeyva added feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. labels Oct 26, 2021
@jasnell
Copy link
Member

jasnell commented Oct 26, 2021

+1 to this. It would be a good addition.

@dubiousjim
Copy link

The whatwg spec gives an example implementation. (Below snippet incorporates some fixes I proposed to the spec, and adds in start/stop options.)

    const fsp = require('node:fs/promises');
    const DEFAULT_CHUNK_SIZE = 65536; // 64K, perhaps make 4096K or 512K?
    function openReadableFileStream(path, start=0, stop=Number.MAX_SAFE_INTEGER) {
        let fileHandle;
        return new ReadableStream({
            type: 'bytes',
            autoAllocateChunkSize: DEFAULT_CHUNK_SIZE,
            async start() {
                fileHandle = await fsp.open(path, 'r');
            },
            async pull(ctrl) {
                const v = ctrl.byobRequest.view;
                const { bytesRead } = await fileHandle.read(v, 0, Math.min(v.byteLength, stop - start), start);
                if (bytesRead === 0) {
                    await fileHandle.close();
                    ctrl.close();
                    ctrl.byobRequest.respond(0);
                } else {
                    start += bytesRead;
                    ctrl.byobRequest.respond(bytesRead);
                }
            },
            cancel() {
                return fileHandle.close();
            }
        });
    };

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label May 28, 2022
@github-actions
Copy link
Contributor

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@targos targos moved this from Pending Triage to Stale in Node.js feature requests Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. stale
Projects
None yet
Development

No branches or pull requests

4 participants