Readable

public protocol Readable

Protocol for byte-source streams.

A single read(into:) call reads up to buf.count bytes into the provided slice and returns how many actually landed. A return of 0 means end-of-stream; a partial read (n < buf.count) is not an error — the caller is expected to loop, or to use readExact / readAll when a specific shape is required.

Examples

public struct DigitsReader: Readable { var next: UInt8 public mutating func read(into buf: ArraySlice[UInt8]) -> Result[Int64, IoError] { if buf.count == 0 { return .Ok(0) } buf.pointer.write(self.next); self.next = self.next + 1; .Ok(1) } }

Methods

mutating func read(into: ArraySlice[UInt8]) -> Result[Int64, IoError]

Reads up to buf.count bytes; returns the number of bytes actually written, with 0 signalling EOF.

Defined in lang/std/io/read.ks