Interface FileBlob

Blob powered by the fastest system calls available for operating on files.

This Blob is lazy. That means it won't do any work until you read from it.

  • size will not be valid until the contents of the file are read at least once.
  • type is auto-set based on the file extension when possible

Example

const file = Bun.file("./hello.json");
console.log(file.type); // "application/json"
console.log(await file.text()); // '{"hello":"world"}'

Example

await Bun.write(
Bun.file("./hello.txt"),
"Hello, world!"
);

Hierarchy

  • Blob
    • FileBlob

Properties

Methods

Properties

size: number
type: string

Methods

  • Read the data from the blob as an ArrayBuffer.

    This copies the data into a new ArrayBuffer.

    Returns Promise<ArrayBuffer>

  • Returns Promise<ArrayBuffer>

  • Read the data from the blob as a JSON object.

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

    Type Parameters

    • TJSONReturnType = unknown

    Returns Promise<TJSONReturnType>

  • Read the contents of the Blob as a JSON object

    Warn

    in browsers, this function is only available for Response and Request

    Returns Promise<any>

  • Offset any operation on the file starting at begin and ending at end. end is relative to 0

    Similar to TypedArray.subarray. Does not copy the file, open the file, or modify the file.

    If begin > 0, Bun.write() will be slower on macOS

    Parameters

    • Optional begin: number

      start offset in bytes

    • Optional end: number

      absolute offset in bytes (relative to 0)

    Returns FileBlob

  • Offset any operation on the file starting at begin and ending at end. end is relative to 0

    Similar to TypedArray.subarray. Does not copy the file, open the file, or modify the file.

    If begin > 0, Bun.write() will be slower on macOS

    Parameters

    • Optional begin: number

      start offset in bytes

    • Optional end: number

      absolute offset in bytes (relative to 0)

    Returns FileBlob

  • Read the data from the blob as a ReadableStream.

    Returns ReadableStream<Uint8Array>

  • Read the data from the blob as a string. It will be decoded from UTF-8.

    Returns Promise<string>

  • Returns Promise<string>

Generated using TypeDoc