Skip to content

class IO::Stapled
inherits IO

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.

Class methods

.pipe(read_blocking : Bool = false, write_blocking : Bool = false

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).

View source

.pipe(read_blocking : Bool = false, write_blocking : Bool = false) : Tuple(self, self)

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

View source

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

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

View source

Methods

#close : Nil

Closes this IO.

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

View source

#closed? : Bool

Returns true if this IO is closed.

Underlying IOs might have a different status.

View source

#flush : self

Flushes writer.

View source

#gets(delimiter : Char, limit : Int, chomp = false) : String?

Gets a string from reader.

View source

#peek : Bytes?

Peeks into reader.

View source

#read(slice : Bytes)

Reads a slice from reader.

View source

#read_byte : UInt8?

Reads a single byte from reader.

View source

#skip(bytes_count : Int) : Nil

Skips reader.

View source

#skip_to_end : Nil

Skips reader.

View source

#sync_close=(sync_close : Bool)

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

View source

#sync_close? : Bool

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

View source

#write(slice : Bytes) : Nil

Writes a slice to writer.

View source

#write_byte(byte : UInt8)

Writes a byte to writer.

View source