class

IO::Stapled

Inherits IO / Reference / Object

This class staples together two unidirectional IOs to form a single, bidirectional IO.

Example (loopback):

io = IO::Stapled.new(*IO.pipe)
io.puts "linus"
io.gets # => "linus"

Most methods simply delegate to the underlying IOs.

Constructors

new(reader : IO, writer : IO, sync_close : Bool = false)

Creates a new IO::Stapled which reads from reader and writes to writer.

Source

Class methods

pipe(read_blocking : Bool | Nil = nil, write_blocking : Bool | Nil = nil, &)

Creates a pair of bidirectional pipe endpoints connected with each other and passes them to the given block.

Both endpoints and the underlying IOs are closed after the block (even if sync_close? is false).

Source
pipe(read_blocking : Bool | Nil = nil, write_blocking : Bool | Nil = nil) : Tuple(self, self)

Creates a pair of bidirectional pipe endpoints connected with each other and returns them in a Tuple.

Source

Instance methods

close

Closes this IO.

If sync_close? is true, it will also close the underlying IOs.

Source
closed?

Returns true if this IO is closed.

Underlying IOs might have a different status.

Source
flush

Flushes writer.

Source
gets(delimiter : Char, limit : Int, chomp = false) : String | Nil

Gets a string from reader.

Source
peek

Peeks into reader.

Source
read(slice : Bytes) : Int32

Reads a slice from reader.

Source
read_byte

Reads a single byte from reader.

Source
skip(bytes_count : Int) : Nil

Skips reader.

Source
skip_to_end

Skips reader.

Source
sync_close=(sync_close : Bool)

If #sync_close? is true, closing this IO will close the underlying IOs.

Source
sync_close?

If #sync_close? is true, closing this IO will close the underlying IOs.

Source
write(slice : Bytes) : Nil

Writes a slice to writer.

Source
write_byte(byte : UInt8) : Nil

Writes a byte to writer.

Source