class

Compress::Gzip::Reader

Inherits IO::Buffered / IO / Reference / Object

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"

Constructors

new(io : IO, sync_close : Bool = false)

Creates a new reader from the given io.

Source
new(filename : String)

Creates a new reader from the given filename.

Source

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.

Source
open(filename : String, &)

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

Source

Instance methods

closed?

Returns true if this reader is closed.

Source
header

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

Source
sync_close=(sync_close : Bool)

Whether to close the enclosed IO when closing this reader.

Source
sync_close?

Whether to close the enclosed IO when closing this reader.

Source
unbuffered_close

Closes this reader.

Source
unbuffered_flush

Flushes the wrapped IO.

TODO: Add return type restriction Nil

Source
unbuffered_read(slice : Bytes) : Int32

See IO#read.

Source
unbuffered_rewind

Rewinds the wrapped IO.

TODO: Add return type restriction Nil

Source
unbuffered_write(slice : Bytes) : NoReturn

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

Source