method

bun.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. The promise rejects once the holes read from the archive's sparse files add up to more than 1,024 times the size of the archive. Up to 64 MiB are always read, and never more than 1 GiB.

@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). Equivalent to 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 an application/x-www-form-urlencoded body.

    The blob's type property determines 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 new Blob with the bytes from start up to but not including end. Negative indices count from the end.

    @param start

    byte offset to start at. Defaults to 0.

    @param end

    byte offset to stop at. Defaults to size.

    @param contentType

    the type of the new 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