Skip to content

Stdin[T]

The process's standard input.

Obtained as shell.stdin.

Every handle reads through one shared buffered reader, so mixing iteration with read picks up exactly where the other left off. What differs between handles is only how they frame that stream.

A function that accepts an Io, such as compress.decompress, reads through the same reader.

Inherits from: std.Iter[T], io.Io

Fields

readable @ Bool [get]

Whether the stream reads, which it always does.

Methods

(eq) other -> Bool

Compares two handles, which are equal when they frame the stream the same way.

Parameters

NameTypeDescription
other Value

(iter)() -> Stdin[T]

Iterates the stream, yielding lines by default.

A line includes its terminator, so chomp is how you ask for one without:

for line = shell.stdin.chomp()
  if (line == "--")
    break
let body = shell.stdin.read()

(next)() -> T

Yields the next line or chunk.

chunks … -> Stdin[Bin]

Returns a handle that yields Bin chunks of at most size bytes, as much as each read returns.

Parameters

NameTypeDescription
size? Int Most bytes per chunk. 65536 by default.

Example

for chunk = shell.stdin.chunks()
  hasher.update $chunk

close()

Does nothing: the process's input stays open.

lines() -> Stdin[Str]

Returns a handle that yields lines.

This is the default framing, so it is only needed to undo a previous chunks.

read … -> Bin

Reads raw bytes.

With a size this is a single read, which may return fewer bytes than asked for, as fs.BaseFile.read does. Without one it reads to end of stream.

Parameters

NameTypeDescription
size? Int Maximum bytes to read. Unbounded when omitted.

Returns

An empty value at the end of the stream.

Example

let rest = shell.stdin.read()
let head = shell.stdin.read 64