Compressing and Archiving Files with Gzip and Tar : zip « Development « Ruby






Compressing and Archiving Files with Gzip and Tar


require 'zlib'

file = 'compressed.gz'
Zlib::GzipWriter.open(file) do |gzip|
  gzip << "this is a test."
  gzip.close
end

open(file, 'rb') { |f| f.read(10) }

Zlib::GzipReader.open(file) { |gzip| puts gzip.read }

 








Related examples in the same category

1.Append to a zip file
2.Inflate and deflate a string