Writes (streams) zip entries to an IO
.
require "compress/zip" File.open("./file.zip", "w") do |file| Compress::Zip::Writer.open(file) do |zip| # Add a file with a String content zip.add "foo.txt", "contents of foo" # Add a file and write data to it through an IO zip.add("bar.txt") do |io| io << "contents of bar" end # Add a file by referencing a file in the filesystem # (the file is automatically closed after this call) zip.add("baz.txt", File.open("./some_file.txt")) end end
Creates a new writer to the given io.
Creates a new writer to the given filename.
Creates a new writer to the given io, yields it to the given block, and closes it at the end.
Creates a new writer to the given filename, yields it to the given block, and closes it at the end.
Adds an entry and yields IO
to write that entry's contents.
Adds an entry that will have string as its contents.
Adds an entry that will have bytes as its contents.
Adds an entry that will have its data copied from the given data.
Adds a directory entry that will have the given name.
Closes this zip writer.
Returns true
if this writer is closed.
Sets the zip file comment
Whether to close the enclosed IO
when closing this writer.
Whether to close the enclosed IO
when closing this writer.
Reference
Reference
Object
Object
Creates a new writer to the given io, yields it to the given block, and closes it at the end.
Creates a new writer to the given filename, yields it to the given block, and closes it at the end.
Adds an entry and yields IO
to write that entry's contents.
You can choose the Entry's compression method before adding it.
IO
.You can also set the Entry's time (which is Time.utc
by default) and extra data before adding it to the zip stream.
Adds an entry that will have string as its contents.
Adds an entry that will have bytes as its contents.
Adds an entry that will have its data copied from the given data. If the given data is a ::File
, it is automatically closed after data is copied from it.
Adds a directory entry that will have the given name.
Closes this zip writer.
Sets the zip file comment
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Compress/Zip/Writer.html