Option for stdin
Search the reference...
/
type
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 possibleconst file = Bun.file("./hello.json");
console.log(file.type); // "application/json"
console.log(await file.text()); // '{"hello":"world"}'
A UNIX timestamp indicating when the file was last modified.
The name or path of the file, as specified in the constructor.
Returns a promise that resolves to the contents of the blob as an ArrayBuffer
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())
Deletes the file (same as unlink)
Does the file exist?
This returns true for regular files and FIFOs. It returns false for directories. Note that a race condition can occur where the file is deleted or renamed after this is called but before you open it.
This does a system call to check if the file exists, which can be slow.
If using this in an HTTP server, it's faster to instead use return new Response(Bun.file(path)) and then an error handler to handle exceptions.
Instead of checking for a file's existence and then performing the operation, it is faster to just perform the operation and handle the error.
For empty Blob, this always returns true.
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.
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");
Read the data from the blob as a JSON object.
This first decodes the data from UTF-8, then parses it as JSON.
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, () will be slower on macOS
start offset in bytes
absolute offset in bytes (relative to 0)
MIME type for the new BunFile
Offset any operation on the file starting at begin
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
start offset in bytes
MIME type for the new BunFile
Slice the file from the beginning to the end, optionally with a new MIME type.
MIME type for the new BunFile
Provides useful information about the file.
Returns a readable stream of the blob's contents
Returns a promise that resolves to the contents of the blob as a string
Deletes the file.
Write data to the file. This is equivalent to using Bun.write with a BunFile.
The data to write.
The options to use for the write.
Incremental writer for files and pipes.
This Streams API interface represents a readable stream of byte data. The Fetch API offers a concrete instance of a ReadableStream through the body property of a Response object.
A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.
Returns a promise that resolves to the contents of the blob as an ArrayBuffer
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())
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.
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");
Read the data from the blob as a JSON object.
This first decodes the data from UTF-8, then parses it as JSON.
Returns a readable stream of the blob's contents
Returns a promise that resolves to the contents of the blob as a string
This Fetch API interface represents the response to a request.
This Fetch API interface represents a resource request.
Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching.
Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL.
Returns the kind of resource requested by request, e.g., "document" or "script".
Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header.
Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI]
Returns a boolean indicating whether or not request can outlive the global in which it was created.
Returns request's HTTP method, which is "GET" by default.
Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs.
Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default.
Returns the referrer of request. Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the Referer header of the request being made.
Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer.
Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
Returns the URL of request as a string.
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →type alias Writable | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- Option for stdin