file_streams/write_stream

Use Erlang file write streams in Gleam.

Types

A stream that binary data can be written to.

pub type WriteStream

Functions

pub fn close(stream: WriteStream) -> Result(Nil, FileError)

Closes a write stream.

Because write streams are opened with delayed writes enabled to improve performance, closing a stream can return an error related to flushing recently written data to disk.

pub fn open(filename: String) -> Result(WriteStream, FileError)

Creates a new write stream that writes binary data to a file. Once the stream is no longer needed it should be closed with close.

pub fn sync(stream: WriteStream) -> Result(Nil, FileError)

Syncs a write stream which ensures that any write buffers kept by the operating system (not by the Erlang runtime system) are written to disk.

Because write streams are opened with delayed writes enabled to improve performance, syncing can return an error related to flushing recently written data to disk.

pub fn write_bytes(
  stream: WriteStream,
  bytes: BitArray,
) -> Result(Nil, FileError)

Writes bytes to a write stream.

pub fn write_line(
  stream: WriteStream,
  line: String,
) -> Result(Nil, FileError)

Writes a line to a write stream along with a trailing newline character.

pub fn write_string(
  stream: WriteStream,
  string: String,
) -> Result(Nil, FileError)

Writes a UTF-8 string to a write stream.

Search Document