class BakedFileSystem::BakedFile
- BakedFileSystem::BakedFile
- IO
- Reference
- Object
Overview
BakedFile represents a virtual file in a BakedFileSystem.
Usage
file = MyFileSystem.get("hello-world.txt")
file.path        # => "hello-world.txt"
file.size        # => 12
file.gets_to_end # => "Hello World\n"
file.compressed? # => falseDefined in:
baked_file_system.crConstructors
Instance Method Summary
- 
        #compressed? : Bool
        
          Returns whether this file is compressed. 
- 
        #compressed_size
        
          Returns the compressed size of this virtual file. 
- 
        #path : String
        
          Returns the path in the virtual file system. 
- 
        #read(slice : Bytes)
        
          Reads at most slice.size bytes from this IOinto slice.
- 
        #read
        
          Return the data for this file as a String. 
- 
        #rewind
        
          Rewinds this IO.
- 
        #size : Int32
        
          Returns the size of this virtual file. 
- 
        #to_encoded(compressed = true)
        
          Return the data for this file as a URL-safe Base64-encoded String. 
- 
        #to_slice(compressed)
        
          Return the file's data as a Slice(UInt8) 
- 
        #to_slice : Bytes
        
          Returns a Bytesholding the (compressed) content of this virtual file.
- 
        #write(slice : Bytes) : Nil
        
          Writes the contents of slice into this IO.
- 
        #write_to_io(io, compressed = true)
        
          Write the file's data to the given IO, minimizing any memory copies or unnecessary conversions. 
Constructor Detail
Instance Method Detail
Returns whether this file is compressed. If not, it is decompressed on read.
Returns the compressed size of this virtual file.
See #size for the real size of the (uncompressed) file.
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) # => 0Return the data for this file as a String.
DEPRECATED  BakedFile can be used as an IO directly. Use gets_to_end instead
Rewinds this IO. By default this method raises, but including types
may implement it.
Return the data for this file as a URL-safe Base64-encoded String.
DEPRECATED  BakedFile can be used as an IO directly.
Return the file's data as a Slice(UInt8)
DEPRECATED  BakedFile can be used as an IO directly.
Returns a Bytes holding the (compressed) content of this virtual file.
This data needs to be extracted using a Compress::Gzip::Reader unless #compressed? is true.
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"