Skip to content

Add support for FS.open, FS.close, FS.read, FS.write, - #834

Open
animeshxd wants to merge 1 commit into
ffmpegwasm:mainfrom
animeshxd:fs_open_close_read_write
Open

animeshxd wants to merge 1 commit into
ffmpegwasm:mainfrom
animeshxd:fs_open_close_read_write

Conversation

@animeshxd

Copy link
Copy Markdown

Added read and write methods for handling large file
Here is the example

async function download(url, path) {
    let fd;
    try {
        fd = await ffmpeg.open(path, 'w')
        const resp = await fetch(url);
        const reader = resp.body.getReader();
        while (true) {
            const { done, value } = await reader.read();
            if (done) break;
            await ffmpeg.write(fd, value, 0, value.length)
        }
    }
    finally {
        await ffmpeg.close(fd)
    }
}

@netlify

netlify Bot commented Feb 2, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for ffmpegwasm canceled.

Name Link
🔨 Latest commit 4443577
🔍 Latest deploy log https://app.netlify.com/sites/ffmpegwasm/deploys/679f6858cf498e0008b4bd3a

@animeshxd

animeshxd commented Sep 28, 2025 •

Copy link
Copy Markdown
Author

open and close name is kinna weird 😫, openFile, closeFile would be better or maybe FS namespace

lucasgelfond added a commit that referenced this pull request Sep 29, 2026
For files too large to hold twice in memory, e.g. a download written to the
file system as it arrives (#797). Adapted from community PR #834 by
animeshxd, with a smaller surface:

- open(path, flags) resolves to a file descriptor
- read(fd, length, position?) resolves to the bytes read; empty at the end
- write(fd, data, position?) resolves to the number of bytes written, and
  transfers data like writeFile() unless { transfer: false }
- close(fd)

An unknown descriptor rejects with "EBADF: bad file descriptor".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant