class Zip::Writer
- Zip::Writer
- Reference
- Object
Overview
Zip file writer.
You shouldn't need to instantiate this class directly; use
Zip.write()
instead.
Defined in:
Class Method Summary
-
.new(io : IO, pos : UInt32 = 0, comment : String = "", version : Version = Version::DEFAULT)
Create a new
Writer
object.
Instance Method Summary
-
#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. -
#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.
-
#add_dir(path : String, time : Time = Time.now, comment : String = "") : UInt32
Add empty directory to archive as path and return number of bytes written.
-
#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.
-
#bytes_written : UInt32
Return the total number of bytes written so far.
-
#close
Close this writer and return the total number of bytes written.
-
#closed? : Bool
Is this
Writer
closed?
Class Method Detail
Create a new Writer
object.
You shouldn't need to instantiate this class directly; use
Zip.write()
instead.
Instance Method Detail
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
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
Add empty directory to archive as path and return number of bytes written.
Example:
# write to "foo.zip"
Zip.write("foo.zip") do |zip|
# add a directory named "example-dir"
zip.add_dir("example-dir")
end
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
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