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.
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" Creates a new reader from the given io.
Creates a new reader from the given filename.
Creates a new reader from the given io, yields it to the given block, and closes it at the end.
Creates a new reader from the given filename, yields it to the given block, and closes it at the end.
Returns true if this reader is closed.
Returns the first header in the gzip stream, if any.
Whether to close the enclosed IO when closing this reader.
Whether to close the enclosed IO when closing this reader.
Closes this reader.
Flushes the wrapped IO.
See IO#read.
Rewinds the wrapped IO.
IO::Buffered
IO
IO
Reference
Reference
Reference
Object
Object
Object
Creates a new reader from the given io, yields it to the given block, and closes it at the end.
Creates a new reader from the given filename, yields it to the given block, and closes it at the end.
Flushes the wrapped IO.
TODO Add return type restriction Nil
Rewinds the wrapped IO.
TODO Add return type restriction Nil
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/Compress/Gzip/Reader.html