ReadableStream

public protocol ReadableStream : AnyObject, TextOutputStreamable, CommandRunning

A stream of text. Does as much as possible lazily.

  • Undocumented

    Declaration

    Swift

    var encoding: String.Encoding { get set }
  • Undocumented

    Declaration

    Swift

    var filehandle: FileHandle { get }
  • readSome() Default implementation

    All the text the stream contains so far. If the source is a file this will read everything at once. If the stream is empty and still open this will wait for more content or end-of-file.

    Default Implementation

    Declaration

    Swift

    func readSome() -> String?

    Return Value

    more text from the stream, or nil if we have reached the end.

  • read() Default implementation

    Reads everything at once.

    Default Implementation

    Declaration

    Swift

    func read() -> String
  • lines() Extension method

    Splits stream lazily into lines.

    Declaration

    Swift

    public func lines() -> LazySequence<AnySequence<String>>
  • write(to:) Extension method

    Writes the text in this stream to the given TextOutputStream.

    Declaration

    Swift

    public func write<Target>(to target: inout Target) where Target : TextOutputStream
  • write(to:) Extension method

    Writes the text in this stream to the given WritableStream.

    Declaration

    Swift

    public func write(to target: inout WritableStream)
  • context Extension method

    Undocumented

    Declaration

    Swift

    public var context: Context { get }
  • readSomeData() Extension method

    All the data the stream contains so far. If the source is a file this will read everything at once. If the stream is empty and still open this will wait for more content or end-of-file.

    Declaration

    Swift

    public func readSomeData() -> Data?

    Return Value

    more data from the stream, or nil if we have reached the end.

  • readData() Extension method

    Reads everything at once. Marked with @discardableResult so that the stream can be read before calling .finish() without causing any compiler warnings or requiring developer work-arounds when the result will not be used (see #52 & #57)

    Declaration

    Swift

    @discardableResult
    public func readData() -> Data
  • onOutput(_:) Extension method

    Sets code to be executed whenever there is new output available.

    Note

    if the stream is read from outside of handler, or more than once inside it, it may be called once when stream is closed and empty.

    Declaration

    Swift

    public func onOutput(_ handler: @escaping (ReadableStream) -> Void)
  • onStringOutput(_:) Extension method

    Sets code to be executed whenever there is new text output available.

    Note

    if the stream is read from outside of handler, or more than once inside it, it may be called once when stream is closed and empty.

    Declaration

    Swift

    public func onStringOutput(_ handler: @escaping (String) -> Void)