The path to the file (lazily loaded)
Optional
options: BlobPropertyBagBlob
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
const file = Bun.file(new TextEncoder.encode("./hello.json"));
console.log(file.type); // "application/json"
The path to the file as a byte buffer (the buffer is copied)
Optional
options: BlobPropertyBagBlob
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.const file = Bun.file(fd);
The file descriptor of the file
Optional
options: BlobPropertyBagBlob
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 possibleconst file = Bun.file("./hello.json");
console.log(file.type); // "application/json"
console.log(await file.json()); // { hello: "world" }
await Bun.write(
Bun.file("./hello.txt"),
"Hello, world!"
);
The path to the file (lazily loaded)
Optional
options: BlobPropertyBagBlob
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
const file = Bun.file(new TextEncoder.encode("./hello.json"));
console.log(file.type); // "application/json"
The path to the file as a byte buffer (the buffer is copied)
Optional
options: BlobPropertyBagBlob
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.const file = Bun.file(fd);
The file descriptor of the file
Optional
options: BlobPropertyBagGenerated using TypeDoc
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 possibleExample
Example