Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 128 additions & 8 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,28 @@ declare module "bun" {
input: Blob | NodeJS.TypedArray | ArrayBufferLike | string | BlobPart[] | Archive | ReadableStream,
options?: {
/**
* If writing to a PathLike, set the permissions of the file.
* Set the Unix permissions of the destination file to exactly this mode.
* The process umask does not apply, and a file that already exists is
* changed too.
*
* The new data is never readable through permissions that the mode does
* not give. If the operating system refuses the change, the write is
* rejected and an existing file keeps its contents. A `Bun.file()` input
* is the exception: it is copied first, and the mode is set after the
* copy.
*
* If omitted, an existing file keeps its permissions, and a new file gets
* the default ones, which the process umask limits (typically 0o644).
*
* It has no effect when the destination is a file descriptor. For an input
* other than a `Bun.file()`, it also has no effect on a FIFO or a device.
* Windows has no Unix permissions, so the mode is not applied in this way
* there.
*
* Must be an integer from 0 to 0o777 (511 in decimal).
*
* @throws {TypeError} If the mode is not a number.
* @throws {RangeError} If the mode is not an integer in that range.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
*/
mode?: number;
/**
Expand Down Expand Up @@ -2183,6 +2204,31 @@ declare module "bun" {
destination: BunFile,
input: Response | Request,
options?: {
/**
* Set the Unix permissions of the destination file to exactly this mode.
* The process umask does not apply, and a file that already exists is
* changed too.
*
* The new data is never readable through permissions that the mode does
* not give. If the operating system refuses the change, the write is
* rejected and an existing file keeps its contents. A `Bun.file()` input
* is the exception: it is copied first, and the mode is set after the
* copy.
*
* If omitted, an existing file keeps its permissions, and a new file gets
* the default ones, which the process umask limits (typically 0o644).
*
* It has no effect when the destination is a file descriptor. For an input
* other than a `Bun.file()`, it also has no effect on a FIFO or a device.
* Windows has no Unix permissions, so the mode is not applied in this way
* there.
*
* Must be an integer from 0 to 0o777 (511 in decimal).
*
* @throws {TypeError} If the mode is not a number.
* @throws {RangeError} If the mode is not an integer in that range.
*/
mode?: number;
/**
* If `true`, create the parent directory if it doesn't exist.
*
Expand All @@ -2208,6 +2254,31 @@ declare module "bun" {
destinationPath: PathLike,
input: Response | Request,
options?: {
/**
* Set the Unix permissions of the destination file to exactly this mode.
* The process umask does not apply, and a file that already exists is
* changed too.
*
* The new data is never readable through permissions that the mode does
* not give. If the operating system refuses the change, the write is
* rejected and an existing file keeps its contents. A `Bun.file()` input
* is the exception: it is copied first, and the mode is set after the
* copy.
*
* If omitted, an existing file keeps its permissions, and a new file gets
* the default ones, which the process umask limits (typically 0o644).
*
* It has no effect when the destination is a file descriptor. For an input
* other than a `Bun.file()`, it also has no effect on a FIFO or a device.
* Windows has no Unix permissions, so the mode is not applied in this way
* there.
*
* Must be an integer from 0 to 0o777 (511 in decimal).
*
* @throws {TypeError} If the mode is not a number.
* @throws {RangeError} If the mode is not an integer in that range.
*/
mode?: number;
/**
* If `true`, create the parent directory if it doesn't exist.
*
Expand Down Expand Up @@ -2242,12 +2313,23 @@ declare module "bun" {
input: BunFile,
options?: {
/**
* Set the file permissions of the destination when it is created or overwritten.
* Set the Unix permissions of the destination file to exactly this mode.
* The process umask does not apply, and a file that already exists is
* changed too.
*
* The file is copied first, and the mode is set after the copy. If the
* operating system refuses the change, the write is rejected after the
* copy.
*
* Must be a valid Unix permission mode (0 to 0o777 / 511 in decimal).
* If omitted, defaults to the system default based on umask (typically 0o644).
*
* @throws {RangeError} If the mode is outside the valid range (0 to 0o777).
* It has no effect when the destination is a file descriptor. Windows has
* no Unix permissions, so the mode is not applied in this way there.
*
* Must be an integer from 0 to 0o777 (511 in decimal).
*
* @throws {TypeError} If the mode is not a number.
* @throws {RangeError} If the mode is not an integer in that range.
*
* @example
* ```ts
Expand Down Expand Up @@ -2288,12 +2370,23 @@ declare module "bun" {
input: BunFile,
options?: {
/**
* Set the file permissions of the destination when it is created or overwritten.
* Set the Unix permissions of the destination file to exactly this mode.
* The process umask does not apply, and a file that already exists is
* changed too.
*
* The file is copied first, and the mode is set after the copy. If the
* operating system refuses the change, the write is rejected after the
* copy.
*
* Must be a valid Unix permission mode (0 to 0o777 / 511 in decimal).
* If omitted, defaults to the system default based on umask (typically 0o644).
*
* @throws {RangeError} If the mode is outside the valid range (0 to 0o777).
* It has no effect when the destination is a file descriptor. Windows has
* no Unix permissions, so the mode is not applied in this way there.
*
* Must be an integer from 0 to 0o777 (511 in decimal).
*
* @throws {TypeError} If the mode is not a number.
* @throws {RangeError} If the mode is not an integer in that range.
*
* @example
* ```ts
Expand Down Expand Up @@ -2759,7 +2852,34 @@ declare module "bun" {
*/
write(
data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer | Request | Response | BunFile | ReadableStream,
options?: { highWaterMark?: number },
options?: {
highWaterMark?: number;
/**
* Set the Unix permissions of this file to exactly this mode.
* The process umask does not apply, and a file that already exists is
* changed too.
*
* The new data is never readable through permissions that the mode does
* not give. If the operating system refuses the change, the write is
* rejected and an existing file keeps its contents. A `Bun.file()` input
* is the exception: it is copied first, and the mode is set after the
* copy.
*
* If omitted, an existing file keeps its permissions, and a new file gets
* the default ones, which the process umask limits (typically 0o644).
*
* It has no effect when this file is a file descriptor. For an input
* other than a `Bun.file()`, it also has no effect on a FIFO or a device.
* Windows has no Unix permissions, so the mode is not applied in this way
* there.
*
* Must be an integer from 0 to 0o777 (511 in decimal).
*
* @throws {TypeError} If the mode is not a number.
* @throws {RangeError} If the mode is not an integer in that range.
*/
mode?: number;
},
): Promise<number>;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/webcore/Blob.bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ export const BunWriteOptions = b.dictionary(
{ createPath: b.bool.emptyStringAsNull, mode: b.f64.nullable },
{ allowArray: true, fromJS: true, reportedAs: "options" },
);
/** The `mode` that `BunFile.prototype.write` reads of its options. It does not read one for an S3 file. */
export const BunWriteMode = b.dictionary(
{ mode: b.f64.nullable },
{ allowArray: true, fromJS: true, reportedAs: "options" },
);
/** `options` is also what a write to S3 takes. */
export const write = b.fn({ ...method, args: { destination: b.any, data: b.any, options: b.any } });
Loading
Loading