Skip to content

feat: add declared size support for lazy files#220

Open
Ehesp wants to merge 1 commit into
vercel-labs:mainfrom
Ehesp:feat/lazy-file-declared-size
Open

feat: add declared size support for lazy files#220
Ehesp wants to merge 1 commit into
vercel-labs:mainfrom
Ehesp:feat/lazy-file-declared-size

Conversation

@Ehesp

@Ehesp Ehesp commented May 7, 2026

Copy link
Copy Markdown

This PR adds support for defining a lazy file with metdaata, including a size.

I've got a use-case using the GitHub tree api where I get the file names, but also the size of the file, see https://api.github.com/repos/vercel-labs/just-bash/git/trees/HEAD

When defining in-memory files, such as:

const env = new Bash({
  files: { "/data/file.txt": () => fetch('...').then(r => t.text()) },
});

When stat() (etc) is called on the FS, it performs a fetch request to return metadata (e.g size). So if the user runs a ls -la command on a directory with say 100 lazy-loaded files, this would be 100 network requests.

This PR adds support for defining the metadata upfront, so content loading is deferred until the content itself is actually needed, e.g:

    "/data/indexed.bin": {
      lazy: async () =>
        new Uint8Array(
          await (await fetch("https://example.com/indexed.bin")).arrayBuffer(),
        ),
      size: 1024,
    },

With this, the content isn't fetched until it's actually needed since we provide the metadata upfront.

Without this, I basically need to re-implement my own file system instance, re-building all of the complexity which the built in ones provided out of the box.

@Ehesp Ehesp requested a review from cramforce as a code owner May 7, 2026 12:01
@vercel

vercel Bot commented May 7, 2026

Copy link
Copy Markdown

@Ehesp is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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