gossamer/writable_stream

Types

pub type UnderlyingSink(a) {
  Start(fn(default_controller.DefaultController) -> Nil)
  Write(
    fn(a, default_controller.DefaultController) -> promise.Promise(
      Nil,
    ),
  )
  Close(fn() -> promise.Promise(Nil))
  Abort(fn(dynamic.Dynamic) -> promise.Promise(Nil))
}

Constructors

A destination stream for writing bytes or objects.

See WritableStream on MDN.

pub type WritableStream(a)

Values

pub fn abort(
  stream: WritableStream(a),
  reason reason: r,
) -> promise.Promise(Result(Nil, js_error.JsError))

Aborts the stream. Returns an error if the underlying sink’s abort callback throws or returns a rejecting promise.

pub fn close(
  stream: WritableStream(a),
) -> promise.Promise(Result(Nil, js_error.JsError))

Closes the stream after all writes complete. Returns an error if the underlying sink’s close callback throws or returns a rejecting promise.

pub fn from_write(
  write: fn(a, default_controller.DefaultController) -> promise.Promise(
    Nil,
  ),
) -> WritableStream(a)

Creates a WritableStream from only a Write callback — use when the sink just needs to handle incoming chunks.

pub fn get_writer(
  stream: WritableStream(a),
) -> Result(writer.Writer(a), js_error.JsError)

Acquires a Writer that locks the stream. Returns an error if the stream is already locked.

pub fn is_locked(stream: WritableStream(a)) -> Bool

Checks whether the stream is locked to a writer.

pub fn new(
  sink: List(UnderlyingSink(a)),
) -> Result(WritableStream(a), js_error.JsError)

Creates a WritableStream driven by the given underlying-sink callbacks (Start, Write, Close, Abort). Returns an error if the Start callback throws synchronously.

Search Document