module IO::Buffered

Overview

TheIO::Buffered mixin enhances anIO 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 : Int32 #

Return the buffer size used


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


def close : Nil #

Flushes and closes the underlyingIO.


def flush : self #

Flushes any buffered data and the underlyingIO. Returnsself.


def flush_on_newline=(flush_on_newline : Bool) : Bool #

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


def flush_on_newline? : Bool #

Determines if thisIO flushes automatically when a newline is written.


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.


def pos : Int64 #

Returns the current position (in bytes) in thisIO.

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

file = File.new("testfile")
file.pos     # => 0
file.gets(2) # => "he"
file.pos     # => 2

def read(slice : Bytes) : Int32 #

Buffered implementation ofIO#read(slice).


def read_buffering=(read_buffering : Bool) : Bool #

Turns on/offIOread buffering.


def read_buffering? : Bool #

Determines whether thisIO buffers reads.


def rewind : self #

Rewinds the underlyingIO. Returnsself.


def sync=(sync : Bool) : Bool #

Turns on/offIOwrite buffering. Whensync is set totrue, no buffering will be done (that is, writing to thisIO is immediately synced to the underlyingIO).


def sync? : Bool #

Determines if thisIO does write buffering. Iftrue, no buffering is done.


abstract def unbuffered_close #

Closes the wrappedIO.

TODO Add return type restrictionNil


abstract def unbuffered_flush #

Flushes the wrappedIO.

TODO Add return type restrictionNil


abstract def unbuffered_read(slice : Bytes) #

Reads at mostslice.size bytes from the wrappedIO intoslice. Returns the number of bytes read.

TODO Add return type restrictionInt32


abstract def unbuffered_rewind #

Rewinds the wrappedIO.

TODO Add return type restrictionNil


abstract def unbuffered_write(slice : Bytes) #

Writesslice entirely into the wrappedIO.

TODO Add return type restrictionNil


def write(slice : Bytes) : Nil #

Buffered implementation ofIO#write(slice).