Class: Morpheus::Morpkg::ZipFileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/morpheus/morpkg.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:

directoryToZip = "/tmp/input"
outputFile = "/tmp/out.zip"
zf = ZipFileGenerator.new(directoryToZip, outputFile)
zf.write()

Instance Method Summary collapse

Constructor Details

#initialize(inputDir, outputFile) ⇒ ZipFileGenerator

Initialize with the directory to zip and the location of the output archive.



85
86
87
88
# File 'lib/morpheus/morpkg.rb', line 85

def initialize(inputDir, outputFile)
  @inputDir = inputDir
  @outputFile = outputFile
end

Instance Method Details

#writeObject

Zip the input directory.



91
92
93
94
95
96
# File 'lib/morpheus/morpkg.rb', line 91

def write()
  entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..")
  io = Zip::File.open(@outputFile, Zip::File::CREATE);
  writeEntries(entries, "", io)
  io.close();
end