Sha256: 103175935f1f41c846e2eeaa9162065f7e057f0efd790440d030435eb8dfd1df
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
module Rpub # Wrapper around a `ZipOutputStream` object provided by the `rubyzip` gem. # This writes string contents straight into a zip file, without first saving # them to disk. class Compressor # @return [ZipOutputStream] attr_reader :zip # Convenience method for opening a stream, allowing content to be written # and finally closing the stream again. def self.open(filename) compressor = new(filename) yield compressor compressor.close end # @param [String] filename of the archive to write to disk def initialize(filename) @zip = Zip::ZipOutputStream.new(filename) end # Close the zip stream and write the file to disk. def close zip.close end # Store a file in the archive without any compression. # # @param [String] filename under the which the data should be stored # @param [#to_s] content to be compressed def store_file(filename, content) zip.put_next_entry filename, nil, nil, Zip::ZipEntry::STORED, Zlib::NO_COMPRESSION zip.write content.to_s end # Store a file with maximum compression in the archive. # # @param [String] filename under the which the data should be stored # @param [#to_s] content to be compressed def compress_file(filename, content) zip.put_next_entry filename, nil, nil, Zip::ZipEntry::DEFLATED, Zlib::BEST_COMPRESSION zip.write content.to_s end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rpub-0.2.0 | lib/rpub/compressor.rb |
rpub-0.1.0 | lib/rpub/compressor.rb |