class Zip::Archive

Overview

Input archive.

Use Zip.read() instead of instantiating this class directly.

Included Modules

Defined in:

Class Method Summary

Instance Method Summary

Class Method Detail

def self.new(io : Source) #

Create new Zip::Archive from input Zip::Source.

Use Zip.read() instead of calling this method directly.


Instance Method Detail

def [](path : String) : Entry #

Get Zip::Entry by path.

Example:

# get bar.txt and write it into memory io
io = MemoryIO.new
zip["bar.txt"].write(io)

def [](id : Int) : Entry #

Get Zip::Entry by number.

Example:

# write contents of third entry from archive into memory io
io = MemoryIO.new
zip[2].write(io)

def []?(id : Int) : Entry | Nil #

Get Zip::Entry by number, or nil if it doesn't exist

Example:

# write contents of third entry from archive into memory io
if e = zip[2]?
  io = MemoryIO.new
  e.write(io)
end

def []?(path : String) : Entry | Nil #

Return Zip::Entry from path, or nil if it doesn't exist.

Example:

# write contents of "bar.txt" into memory io if it exists
if e = zip["bar.txt"]?
  io = MemoryIO.new
  e.write(io)
end

def comment : String #

Get the Archive comment as a String.

Example:

Zip.read("foo.zip") do |zip|
  # print archive comment
  puts "comment: #{zip.comment}"
end

def each(*args, **options, &block) #

Iterate over the entries in this Archive, or, if called without a block, return a lazy iterator.

Example:

Zip.read("foo.zip") do |zip|
  zip.each do |e|
    type = e.dir? ? "directory" : "file"
    puts "#{e.path} is a #{type}"
  end
end

def each(*args, **options) #

Iterate over the entries in this Archive, or, if called without a block, return a lazy iterator.

Example:

Zip.read("foo.zip") do |zip|
  zip.each do |e|
    type = e.dir? ? "directory" : "file"
    puts "#{e.path} is a #{type}"
  end
end

def entries : Array(Zip::Entry) #

Return an array of entries in this Archive.

Example:

Zip.read("foo.zip") do |zip|
  # get an array of entries in this archive
  entries = zip.entries
end

def size(*args, **options, &block) #

Return the number of entries in this Archive.

Example:

Zip.read("foo.zip") do |zip|
  puts "foo.zip has #{zip.size} entries"
end

def size(*args, **options) #

Return the number of entries in this Archive.

Example:

Zip.read("foo.zip") do |zip|
  puts "foo.zip has #{zip.size} entries"
end