method

BunFile.writer

options?: { highWaterMark: number }

Incremental writer for files and pipes.

Referenced types

interface FileSink

Fast incremental writer for files and pipes.

This uses the same interface as ArrayBufferSink, but writes to a file or pipe.

  • error?: Error
    ): number | Promise<number>;

    Close the file descriptor. This also flushes the internal buffer.

    @param error

    Optional error to associate with the close operation

    @returns

    Number of bytes written or a Promise resolving to the number of bytes

  • flush(): number | Promise<number>;

    Flush the internal buffer, committing the data to disk or the pipe.

    @returns

    Number of bytes flushed or a Promise resolving to the number of bytes

  • ref(): void;

    For FIFOs & pipes, keep Bun's process alive until the pipe closes.

    By default, this is managed automatically: while the stream is open the process stays alive, and once the other end hangs up or the stream closes, the process exits.

    If you previously called unref, call this to re-enable automatic management.

    Internally, calls to ref and unref are reference counted. The count starts at 1.

    If the file is not a FIFO or pipe, ref and unref do nothing. If the pipe is already closed, this does nothing.

  • options?: { highWaterMark: number }
    ): void;

    Start the file sink with provided options.

    @param options

    Configuration options for the file sink

  • unref(): void;

    For FIFOs & pipes, allow Bun's process to exit while the stream is open.

    If the file is not a FIFO or pipe, ref and unref do nothing. If the pipe is already closed, this does nothing.

  • chunk: string | ArrayBuffer | SharedArrayBuffer | ArrayBufferView<ArrayBufferLike>
    ): number | Promise<number>;

    Write a chunk of data to the file.

    If the file descriptor is not writable yet, the data is buffered.

    @param chunk

    The data to write

    @returns

    Number of bytes written or, if the write is pending, a Promise resolving to the number of bytes