Skip to content

Instantly share code, notes, and snippets.

@jmcnevin
Created October 9, 2012 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcnevin/3860263 to your computer and use it in GitHub Desktop.
Save jmcnevin/3860263 to your computer and use it in GitHub Desktop.
Jruby 1.7 corrupts file
#!/usr/bin/env ruby -w
require 'zlib'
in_file = File.join('test/examples/rgb.jpg')
out_file = 'rgb.out.jpg'
gz_file = 'test.jpg.gz'
chunk_size = 2**16
Zlib::GzipWriter.open(gz_file) do |gz|
File.open(in_file) do |f|
gz.write(f.read(chunk_size)) until f.eof?
end
end
Zlib::GzipReader.open(gz_file) do |gz|
File.open(out_file, 'w') do |f|
f.write(gz.read(chunk_size)) until gz.eof?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment