W3cubDocs

/Crystal

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_sizeSource

Return the buffer size used

def buffer_size=(value)Source

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

def close : NilSource

Flushes and closes the underlying IO.

def flushSource

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

def flush_on_newline=(flush_on_newline)Source

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

def flush_on_newline?Source

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

def peek : Bytes?Source

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 read(slice : Bytes)Source

Buffered implementation of IO#read(slice).

def read_buffering=(read_buffering)Source

Turns on/off IO read buffering.

def read_buffering?Source

Determines whether this IO buffers reads.

def rewindSource

Rewinds the underlying IO. Returns self.

def sync=(sync)Source

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

def sync?Source

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

abstract def unbuffered_closeSource

Closes the wrapped IO.

abstract def unbuffered_flushSource

Flushes the wrapped IO.

abstract def unbuffered_read(slice : Bytes)Source

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

abstract def unbuffered_rewindSource

Rewinds the wrapped IO.

abstract def unbuffered_write(slice : Bytes)Source

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

def write(slice : Bytes) : NilSource

Buffered implementation of IO#write(slice).

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/IO/Buffered.html