module

IO::Buffered

The IO::Buffered mixin enhances an IO with input/output buffering.

The buffering behaviour can be turned on/off with the #sync= and #read_buffering= methods.

Additionally, several methods, like #gets, are implemented in a more efficient way.

Instance methods

buffer_size

Return the buffer size used

Source
buffer_size=(value)

Set the buffer size of both the read and write buffer Cannot be changed after any of the buffers have been allocated

Source
close

Flushes and closes the underlying IO.

Source
flush

Flushes any buffered data and the underlying IO. Returns self.

Source
flush_on_newline=(flush_on_newline : Bool) : Bool

Turns on/off flushing the underlying IO when a newline is written.

Source
flush_on_newline?

Determines if this IO flushes automatically when a newline is written.

Source
peek

Returns the bytes hold in the read buffer.

This method only performs a read to return peek data if the current buffer is empty: otherwise no read is performed and whatever is in the buffer is returned.

Source
pos

Returns the current position (in bytes) in this IO.

File.write("testfile", "hello")

file = File.new("testfile")
file.pos     # => 0
file.gets(2) # => "he"
file.pos     # => 2
Source
read(slice : Bytes) : Int32

Buffered implementation of IO#read(slice).

Source
read_buffering=(read_buffering : Bool) : Bool

Turns on/off IO read buffering.

Source
read_buffering?

Determines whether this IO buffers reads.

Source
rewind

Rewinds the underlying IO. Returns self.

Source
sync=(sync : Bool) : Bool

Turns on/off IO write buffering. When sync is set to true, no buffering will be done (that is, writing to this IO is immediately synced to the underlying IO).

Source
sync?

Determines if this IO does write buffering. If true, no buffering is done.

Source
unbuffered_close

Closes the wrapped IO.

TODO: Add return type restriction Nil

Source
unbuffered_flush

Flushes the wrapped IO.

TODO: Add return type restriction Nil

Source
unbuffered_read(slice : Bytes)

Reads at most slice.size bytes from the wrapped IO into slice. Returns the number of bytes read.

TODO: Add return type restriction Int32

Source
unbuffered_rewind

Rewinds the wrapped IO.

TODO: Add return type restriction Nil

Source
unbuffered_write(slice : Bytes)

Writes slice entirely into the wrapped IO.

TODO: Add return type restriction Nil

Source
write(slice : Bytes) : Nil

Buffered implementation of IO#write(slice).

Source