I have a service that delivers zip files over the Internet. Zip contains executable files for the Windows platform.
I use the RubyZip library to compress the file, but this process damages the binary. On my local server, we use the zip command through a system call, and it works fine.
The zip command is not available in Heroku, and I'm just out of options.
I am using this class:
require 'zip/zip'
class ZipFileGenerator
def initialize(inputDir, outputFile)
@inputDir = inputDir
@outputFile = outputFile
end
def write()
entries = Dir.entries(@inputDir); entries.delete("."); entries.delete("..")
io = Zip::ZipFile.open(@outputFile, Zip::ZipFile::CREATE);
writeEntries(entries, "", io)
io.close();
end
private
def writeEntries(entries, path, io)
entries.each { |e|
zipFilePath = path == "" ? e : File.join(path, e)
diskFilePath = File.join(@inputDir, zipFilePath)
puts "Deflating " + diskFilePath
if File.directory?(diskFilePath)
io.mkdir(zipFilePath)
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
writeEntries(subdir, zipFilePath, io)
else
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
end
}
end
end
source
share