class Zip::Writer

Defined in:

Class Method Summary

Instance Method Summary

Class Method Detail

def self.new(io : IO, pos : UInt32 = 0, comment : String = "", version : Version = Version::DEFAULT) #

Create a new Writer object.

You shouldn't need to instantiate this class directly; use Zip.write() instead.


Instance Method Detail

def add(path : String, io : IO, method : CompressionMethod = CompressionMethod::DEFLATE, time : Time = Time.now, comment : String = "") : UInt32 #

Read data from IO io, write it to path in archive, then return the number of bytes written.

Example:

# create IO from "/path/to/bar.txt" File.open("/path/to/bar.txt, "rb") do |io| # write to "foo.zip" Zip.write("foo.zip") do |zip| # add "bar.txt" with contents of given IO zip.add("bar.txt", io) end end


def add(path : String, data : String | Bytes, method : CompressionMethod = CompressionMethod::DEFLATE, time : Time = Time.now, comment : String = "") : UInt32 #

Write data to path in archive and return number of bytes written.

Example:

# write to "foo.zip" Zip.write("foo.zip") do |zip| # add "bar.txt" with contents "hello!" zip.add("bar.txt", "hello!") end


def add_file(path : String, file_path : String, method : CompressionMethod = CompressionMethod::DEFLATE, time : Time = Time.now, comment : String = "") : UInt32 #

Add local file file_path to archive as path and return number of bytes written.

Example:

# write to "foo.zip" Zip.write("foo.zip") do |zip| # add local file "/path/to/bar.txt" as "bar.txt" zip.add_file("bar.txt", "/path/to/bar.txt") end


def bytes_written : UInt32 #

Return the total number of bytes written so far.

Example:

Zip.write("foo.zip") do |zip| # add "bar.txt" zip.add_file("bar.txt", "/path/to/bar.txt")

# print number of bytes written so far
puts "bytes written so far: #{zip.bytes_written}"

end


def close #

Close this writer and return the total number of bytes written.


def closed? : Bool #

Is this Writer closed?