Mfiles
Bun

method

Archive.files

glob?: string | readonly string[]
): Promise<Map<string, File>>;

Get the archive contents as a Map of File objects.

Each file in the archive is returned as a File object with:

  • name: The file path within the archive
  • lastModified: The file's modification time from the archive
  • Standard Blob methods (text(), arrayBuffer(), stream(), etc.)

Only regular files are included; directories are not returned. File contents are loaded into memory, so for large archives consider using extract() instead.

@param glob

Optional glob pattern(s) to filter files. Supports the same syntax as Bun.Glob, including negation patterns (prefixed with !). Patterns are matched against paths normalized to use forward slashes (/).

@returns

A promise that resolves with a Map where keys are file paths (always using forward slashes / as separators) and values are File objects

Get all files:

const entries = await archive.files();
for (const [path, file] of entries) {
  console.log(`${path}: ${file.size} bytes`);
}

Referenced types

class File

Provides information about files and allows JavaScript in a web page to access their content.

MDN Reference

  • readonly lastModified: number
  • readonly name: string
  • readonly size: number
  • readonly type: string
  • Returns a promise that resolves to the contents of the blob as an ArrayBuffer

  • bytes(): Promise<Uint8Array<ArrayBufferLike>>;

    Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes) its the same as new Uint8Array(await blob.arrayBuffer())

  • formData(): Promise<FormData>;

    Read the data from the blob as a FormData object.

    This first decodes the data from UTF-8, then parses it as a multipart/form-data body or a application/x-www-form-urlencoded body.

    The type property of the blob is used to determine the format of the body.

    This is a non-standard addition to the Blob API, to make it conform more closely to the BodyMixin API.

  • ): Image;

    Wrap this blob in a Bun.Image pipeline. Equivalent to new Bun.Image(this, options) — the constructor is synchronous (the underlying read happens lazily when an Image terminal is awaited), so this works on Bun.file(), Bun.s3(), fd-backed and in-memory blobs alike:

    await Bun.file("photo.jpg").image().resize(400).webp().write("thumb.webp");
    
  • json(): Promise<any>;

    Read the data from the blob as a JSON object.

    This first decodes the data from UTF-8, then parses it as JSON.

  • start?: number,
    end?: number,
    contentType?: string
    ): Blob;
  • Returns a readable stream of the blob's contents

  • text(): Promise<string>;

    Returns a promise that resolves to the contents of the blob as a string