module IO::Buffered

Overview

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.

Direct including types

Defined in:

io/buffered.cr

Instance Method Summary

Instance Method Detail

def buffer_size #

Return the buffer size used


[View source]
def 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


[View source]
def close : Nil #

Flushes and closes the underlying IO.


[View source]
def flush #

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


[View source]
def peek : Bytes? #

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.


[View source]
def read(slice : Bytes) #

Buffered implementation of IO#read(slice).


[View source]
def read_buffering=(read_buffering) #

Turns on/off IO read buffering.


[View source]
def read_buffering? #

Determines whether this IO buffers reads.


[View source]
def rewind #

Rewinds the underlying IO. Returns self.


[View source]
def sync=(sync) #

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


[View source]
def sync? #

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


[View source]
abstract def unbuffered_close #

Closes the wrapped IO.


[View source]
abstract def unbuffered_flush #

Flushes the wrapped IO.


[View source]
abstract def unbuffered_read(slice : Bytes) #

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


[View source]
abstract def unbuffered_rewind #

Rewinds the wrapped IO.


[View source]
abstract def unbuffered_write(slice : Bytes) #

Writes at most slice.size bytes from slice into the wrapped IO. Returns the number of bytes written.


[View source]
def write(slice : Bytes) : Nil #

Buffered implementation of IO#write(slice).


[View source]