Class: Grache::ZipGenerator
- Inherits:
-
Object
- Object
- Grache::ZipGenerator
- Defined in:
- lib/grache/zip/zip_generator.rb
Overview
This is a simple example which uses rubyzip to recursively generate a zip file from the contents of a specified directory. The directory itself is not included in the archive, rather just its contents.
Usage: require /path/to/the/ZipFileGenerator/Class directoryToZip = “/tmp/input” outputFile = “/tmp/out.zip” zf = ZipFileGenerator.new(directoryToZip, outputFile) zf.write()
Instance Method Summary collapse
-
#initialize(inputDir, outputFile) ⇒ ZipGenerator
constructor
Initialize with the directory to zip and the location of the output archive.
-
#write(root = '') ⇒ Object
Zip the input directory.
Constructor Details
#initialize(inputDir, outputFile) ⇒ ZipGenerator
Initialize with the directory to zip and the location of the output archive.
20 21 22 23 |
# File 'lib/grache/zip/zip_generator.rb', line 20 def initialize(inputDir, outputFile) @inputDir = inputDir @outputFile = outputFile end |
Instance Method Details
#write(root = '') ⇒ Object
Zip the input directory.
26 27 28 29 30 31 32 33 34 |
# File 'lib/grache/zip/zip_generator.rb', line 26 def write(root = '') entries = Dir.entries(@inputDir) entries.delete('.') entries.delete('..') io = Zip::File.open(@outputFile, Zip::File::CREATE); writeEntries(entries, '', io, root) io.close(); end |