Compress::LZ4::Writer
A write-only IO object to compress data in the LZ4 format.
Instances of this class wrap another IO object. When you write to this
instance, it compresses the data and writes it to the underlying IO.
NOTE: unless created with a block, close must be invoked after all
data has been written to a LZ4::Writer instance.
Example: compress a file
require "lz4"
File.write("file.txt", "abcd")
File.open("./file.txt", "r") do |input_file|
File.open("./file.lz4", "w") do |output_file|
Compress::LZ4::Writer.open(output_file) do |lz4|
IO.copy(input_file, lz4)
end
end
end
Constructors
Class methods
Creates a new writer for the given io, yields it to the given block, and closes it at its end.
Instance methods
closed?
Returns true if this IO is closed.
IO defines returns false, but including types may override.
compressed_bytes
Sourcefinalize
Sourceread(slice : Bytes)
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
sync_close?
Sourceuncompressed_bytes
Source