Sha256: e27985eaa89f5a6849845e36177b0cb9d3b78fc68453fe48b8f4c6939da0f91f
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
#!/usr/bin/env ruby require "zip" require "pathname" require "shellwords" # c.f. https://github.com/rubyzip/rubyzip/blob/05916bf89181e1955118fd3ea059f18acac28cc8/samples/example_recursive.rb class ZipFileGenerator def initialize(input_dir, output_file) @input_dir = Pathname(input_dir) @output_file = Pathname(output_file) end def write @output_file.delete if @output_file.exist? Zip::File.open(@output_file, Zip::File::CREATE) do |io| write_entries entries_in(@input_dir), "", io end end private def write_entries(entries, path, io) entries.each do |entry| zip_file_path = path == "" ? entry : File.join(path, entry) disk_file_path = File.join(@input_dir, zip_file_path) if File.directory?(disk_file_path) io.mkdir zip_file_path write_entries entries_in(disk_file_path), zip_file_path, io else io.get_output_stream(zip_file_path) do |stream| stream.puts File.open(disk_file_path, "rb").read end end end end private def entries_in(path) entries = Dir.entries(path) entries.delete(".") entries.delete("..") entries.delete(".DS_Store") entries end end path = Pathname.new(ARGV.shift) if path.directory? zf = ZipFileGenerator.new(path, "#{path.basename}.pptx") zf.write else system "unzip #{Shellwords.escape path} -d #{path.basename(".pptx")}" end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
openxml-pptx-0.2.2 | bin/zipflip |
openxml-pptx-0.2.0 | bin/zipflip |