An IO
that wraps another IO
, setting a limit for the number of bytes that can be read.
io = IO::Memory.new "abcde" sized = IO::Sized.new(io, read_size: 3) sized.gets_to_end # => "abc" sized.gets_to_end # => "" io.gets_to_end # => "de"
Creates a new IO::Sized
which wraps io, and can read a maximum of read_size bytes.
Closes this IO
.
Returns true
if this IO
is closed.
Peeks into this IO, if possible.
Reads at most slice.size bytes from this IO
into slice.
Reads a single byte from this IO
.
The number of remaining bytes to be read.
If #sync_close?
is true
, closing this IO
will close the underlying IO
.
If #sync_close?
is true
, closing this IO
will close the underlying IO
.
Writes the contents of slice into this IO
.
IO
IO
Reference
Reference
Object
Object
Peeks into this IO, if possible.
It returns:
nil
if this IO isn't peekableThe returned bytes are only valid data until a next call to any method that reads from this IO is invoked.
By default this method returns nil
, but IO implementations that provide buffering or wrap other IOs should override this method.
Reads at most slice.size bytes from this IO
into slice. Returns the number of bytes read, which is 0 if and only if there is no more data to read (so checking for 0 is the way to detect end of file).
io = IO::Memory.new "hello" slice = Bytes.new(4) io.read(slice) # => 4 slice # => Bytes[104, 101, 108, 108] io.read(slice) # => 1 slice # => Bytes[111, 101, 108, 108] io.read(slice) # => 0
If #sync_close?
is true
, closing this IO
will close the underlying IO
.
If #sync_close?
is true
, closing this IO
will close the underlying IO
.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/IO/Sized.html