class Bakelite::FileIO

Overview

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.

Defined in:

bakelite/file_io.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(chunks : Array(Chunk), size : Int64, compression : CompressionType = CompressionType::None, underlying_io : IO | Nil = nil) #

Instance Method Detail

def close : Nil #
Description copied from class IO

Closes this IO.

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


def closed? : Bool #
Description copied from class IO

Returns true if this IO is closed.

IO defines returns false, but including types may override.


def compression : CompressionType #

def pos : Int64 #
Description copied from class IO

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

def read(slice : Bytes) : Int32 #

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


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

Seeking support: Set, Current, or End


def size : Int64 #

def write(slice : Bytes) : Nil #
Description copied from class IO

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"