class Compress::Gzip::Reader
inherits IO
¶
A read-only IO
object to decompress data in the gzip format.
Instances of this class wrap another IO object. When you read from this instance instance, it reads data from the underlying IO, decompresses it, and returns it to the caller.
Note
A gzip stream can contain zero or more members. If it contains
no members, header
will be nil
. If it contains one or more
members, only the first header will be recorded here. This is
because gzipping multiple members is not common as one usually
combines gzip with tar. If, however, multiple members are present
then reading from this reader will return the concatenation of
all the members.
Example: decompress a gzip file¶
require "compress/gzip"
File.write("file.gzip", Bytes[31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 76, 74, 6, 0, 194, 65, 36, 53, 3, 0, 0, 0])
string = File.open("file.gzip") do |file|
Compress::Gzip::Reader.open(file) do |gzip|
gzip.gets_to_end
end
end
string # => "abc"
Included modules
IO::Buffered
Class methods¶
.open(io : IO, sync_close = false
¶
(io : IO, sync_close = false
Creates a new reader from the given io, yields it to the given block, and closes it at the end.
.open(filename : String
¶
(filename : String
Creates a new reader from the given filename, yields it to the given block, and closes it at the end.