class

Bakelite::FileIO

Inherits IO < Reference < Object

High-performance, read-only streaming IO implementation for Bakelite stored assets. Decompresses chunks on demand into a single active sliding buffer, ensuring peak memory usage remains strictly O(chunk_size) regardless of file size.

Constructors

new(chunks : Array(Chunk), size : Int64, compression : CompressionType = CompressionType::None, underlying_io : IO | Nil = nil)
Source

Instance methods

close

Closes this IO.

IO defines this is a no-op method, but including types may override.

Source
closed?

Returns true if this IO is closed.

IO defines returns false, but including types may override.

Source
compression
Source
pos

Returns the current position (in bytes) in this IO.

The IO class raises on this method, but some subclasses, notable IO::FileDescriptor and IO::Memory implement it.

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

file = File.new("testfile")
file.pos     # => 0
file.gets(2) # => "he"
file.pos     # => 2
Source
read(slice : Bytes) : Int32

Reads up to slice.size bytes into slice. Returns number of bytes read (0 on EOF).

Source
seek(offset : Int, whence : IO::Seek = IO::Seek::Set) : self

Seeking support: Set, Current, or End

Source
size
Source
write(slice : Bytes) : Nil

Writes the contents of slice into this IO.

io = IO::Memory.new
slice = Bytes.new(4) { |i| ('a'.ord + i).to_u8 }
io.write(slice)
io.to_s # => "abcd"
Source