温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/FileSink
点击访问原文链接

Bun.FileSink TypeScript interface | API Reference | Bun

Bun.FileSink TypeScript interface | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/Bun/FileSinkMendMflushMrefMstartMunrefMwrite

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/FileSinkMendMflushMrefMstartMunrefMwrite

interface

FileSinkinterface FileSink

Fast incremental writer for files and pipes.

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

end(error?: Error): number | Promisenumber>;

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 | Promisenumber>;

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, this lets you decide whether Bun's process should remain alive until the pipe is closed.

By default, it is automatically managed. While the stream is open, the process remains alive and once the other end hangs up or the stream closes, the process exits.

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

Internally, it will reference count the number of times this is called. By default, that number is 1

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

start(options?: { highWaterMark: number }): void;

Start the file sink with provided options.

@param options

Configuration options for the file sink

unref(): void;

For FIFOs & pipes, this lets you decide whether Bun's process should remain alive until the pipe is closed.

If you want to allow Bun's process to terminate while the stream is open, call this.

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

write(chunk: string | ArrayBuffer | SharedArrayBuffer | ArrayBufferViewArrayBufferLike>): number | Promisenumber>;

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

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Bun.FileSink TypeScript interface | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    Fast incremental writer for files and pipes. This uses the same interface as ArrayBufferSink, but writes to a file or pipe.