class BakedFileSystem::BakedFile

Defined in:

baked_file_system.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(path : String, mime_type : String, size : Int32, compressed : Bool, slice : Bytes) #

[View source]

Instance Method Detail

def compressed? : Bool #

[View source]
def compressed_size #

Returns the compressed size of this virtual file.

See #size for the real size of the (uncompressed) file.


[View source]
def mime_type : String #

[View source]
def path : String #

[View source]
def read(slice : Bytes) #
Description copied from class IO

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

[View source]
def read #

Return the data for this file as a String.

DEPRECATED BakedFile can be used as an IO directly. Use gets_to_end instead


[View source]
def rewind #
Description copied from class IO

Rewinds this IO. By default this method raises, but including types may implement it.


[View source]
def size : Int32 #

[View source]
def to_encoded(compressed : Bool = true) #

Return the data for this file as a URL-safe Base64-encoded String.

DEPRECATED BakedFile can be used as an IO directly.


[View source]
def to_slice(compressed) #

Return the file's data as a Slice(UInt8)

DEPRECATED BakedFile can be used as an IO directly.


[View source]
def to_slice : Bytes #

Returns a Bytes holding the (compressed) content of this virtual file. This data needs to be extracted using a Gzip::Reader unless #compressed? is true.


[View source]
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"

[View source]
def write_to_io(io : IO, compressed : Bool = true) #

Write the file's data to the given IO, minimizing any memory copies or unnecessary conversions.

DEPRECATED BakedFile can be used as an IO directly.


[View source]