Function file

  • 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.json()); // { hello: "world" }

    Example

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

    Parameters

    • path: string

      The path to the file (lazily loaded)

    • Optional options: BlobPropertyBag

    Returns FileBlob

  • Blob that leverages the fastest system calls available to operate on files.

    This Blob is lazy. It won't do any work until you read from it. Errors propagate as promise rejections.

    Blob.size will not be valid until the contents of the file are read at least once. Blob.type will have a default set based on the file extension

    Example

    const file = Bun.file(new TextEncoder.encode("./hello.json"));
    console.log(file.type); // "application/json"

    Parameters

    • path: Uint8Array | ArrayBufferLike

      The path to the file as a byte buffer (the buffer is copied)

    • Optional options: BlobPropertyBag

    Returns 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.

    Example

    const file = Bun.file(fd);
    

    Parameters

    • fileDescriptor: number

      The file descriptor of the file

    • Optional options: BlobPropertyBag

    Returns 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.json()); // { hello: "world" }

    Example

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

    Parameters

    • path: string

      The path to the file (lazily loaded)

    • Optional options: BlobPropertyBag

    Returns FileBlob

  • Blob that leverages the fastest system calls available to operate on files.

    This Blob is lazy. It won't do any work until you read from it. Errors propagate as promise rejections.

    Blob.size will not be valid until the contents of the file are read at least once. Blob.type will have a default set based on the file extension

    Example

    const file = Bun.file(new TextEncoder.encode("./hello.json"));
    console.log(file.type); // "application/json"

    Parameters

    • path: Uint8Array | ArrayBufferLike

      The path to the file as a byte buffer (the buffer is copied)

    • Optional options: BlobPropertyBag

    Returns 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.

    Example

    const file = Bun.file(fd);
    

    Parameters

    • fileDescriptor: number

      The file descriptor of the file

    • Optional options: BlobPropertyBag

    Returns FileBlob

Generated using TypeDoc