IO::PrefixSuffixBuffer
PrefixSuffixBuffer is an IO that retains the first bytes in the prefix
buffer and the last bytes in the suffix buffer.
When writing more bytes than fit in the buffers, only the start and end bytes
are preserved.
#to_s renders the buffer contents with a message indicating how many
bytes were omitted.
Constructors
Creates an instance using the given buffers.
The maximum size that this instance can consume without omitting data is the sum of the buffer sizes.
Instance methods
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
Appends the buffer to the given IO.
When the total size of the consumed data exceeds the buffer size, the middle part is omitted and replaced by a message that indicates the number of skipped bytes.
Returns a nicely readable and concise string representation of this object, typically intended for users.
This method should usually not be overridden. It delegates to
#to_s(IO) which can be overridden for custom implementations.
Also see #inspect.