Writable

public protocol Writable

Protocol for byte-sink streams.

Conformers expose a single-shot write(from:) and a flush() for buffered implementations. As with Read, a single write may move fewer bytes than supplied — this is not an error; use writeAll to loop until the whole slice is consumed.

Examples

public struct CountingSink: Writable { var written: Int64 = 0 public mutating func write(from buf: ArraySlice[UInt8]) -> Result[Int64, IoError] { self.written = self.written + buf.count; .Ok(buf.count) } public mutating func flush() -> Result[(), IoError] { .Ok(()) } }

Methods

mutating func flush() -> Result[(), IoError]

Pushes any internally buffered bytes to the underlying destination. Unbuffered writers may implement this as a no-op. Errors here can surface conditions deferred from earlier write calls (broken pipe, disk full).

mutating func write(from: ArraySlice[UInt8]) -> Result[Int64, IoError]

Writes up to buf.count bytes; returns how many actually moved. .Ok(0) indicates the sink could accept no more right now (full buffer / would-block); other amounts are partial successes that the caller may retry.

Defined in lang/std/io/write.ks