Class: LambdaWrap::ZipFileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda_wrap/zip_file_generator.rb

Overview

Allows to easily zip a directory recursively. It’s intended for gem internal use only.

From the original example: 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

Constructor Details

#initialize(input_dir, output_file) ⇒ ZipFileGenerator

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



25
26
27
28
# File 'lib/lambda_wrap/zip_file_generator.rb', line 25

def initialize(input_dir, output_file)
    @input_dir = input_dir
    @output_file = output_file
end

Instance Method Details

#writeObject

Zip the input directory.



32
33
34
35
36
37
38
# File 'lib/lambda_wrap/zip_file_generator.rb', line 32

def write
    entries = Dir.entries(@input_dir) - %w(. ..)

    ::Zip::File.open(@output_file, ::Zip::File::CREATE) do |io|
    write_entries entries, '', io
    end
end