Skip to content

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

Creates a new reader from the given io, yields it to the given block, and closes it at the end.

View source

.open(filename : String

Creates a new reader from the given filename, yields it to the given block, and closes it at the end.

View source

.new(io : IO, sync_close = false)

Creates a new reader from the given io.

View source

.new(filename : String)

Creates a new reader from the given filename.

View source

Methods

#closed? : Bool

Returns true if this reader is closed.

View source

#header : Header?

Returns the first header in the gzip stream, if any.

View source

#sync_close=(sync_close)

Whether to close the enclosed IO when closing this reader.

View source

#sync_close? : Bool

Whether to close the enclosed IO when closing this reader.

View source

#unbuffered_close

Closes this reader.

View source

#unbuffered_flush

Flushes the wrapped IO.

View source

#unbuffered_read(slice : Bytes)

See IO#read.

View source

#unbuffered_rewind

Rewinds the wrapped IO.

View source

#unbuffered_write(slice : Bytes) : Nil

Always raises IO::Error because this is a read-only IO.

View source