W3cubDocs

/Crystal

class Compress::Zip::File

Overview

Provides random read access to zip file entries stores inside a File or an IO::Memory.

Example

require "compress/zip"

Compress::Zip::File.open("./file.zip") do |file|
  # Iterate through all entries printing their filename and contents
  file.entries.each do |entry|
    p entry.filename
    entry.open do |io|
      p io.gets_to_end
    end
  end

  # Random access to entries by filename is also provided
  entry = file["some_file.txt"]
  entry.open do |io|
    p io.gets_to_end
  end
end

Defined in:

compress/zip/file.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(io : IO, sync_close = false)Source

Opens a Zip::File for reading from the given io.

def self.new(filename : String)Source

Opens a Zip::File for reading from the given filename.

Class Method Detail

def self.open(io : IO, sync_close = false, &)Source

Opens a Zip::File for reading from the given io, yields it to the given block, and closes it at the end.

def self.open(filename : String, &)Source

Opens a Zip::File for reading from the given filename, yields it to the given block, and closes it at the end.

Instance Method Detail

def [](filename : String) : EntrySource

Returns the entry that has the given filename, or raises KeyError if no such entry exists.

def []?(filename : String) : Entry?Source

Returns the entry that has the given filename, or nil if no such entry exists.

def closeSource

Closes this zip file.

def closed? : BoolSource

Returns true if this zip file is closed.

def comment : StringSource

Returns the zip file comment.

def entries : Array(Entry)Source

Returns all entries inside this zip file.

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Compress/Zip/File.html