I am trying to decompress a file with following Ruby code.
File.open("file_compressed.gz") do |compressed|
File.open("file_decomp","w") do |decompressed|
gz = Zlib::GzipReader.new(compressed)
result = gz.read
decompressed.write(result)
gz.close
end
end
But I am getting following error –
not in gzip format (Zlib::GzipFile::Error)
./features/support/abc/abc_file.rb:44:in `initialize'
When I decompress the same file using gzip command on Mac it produced the correct uncompressed output.
For following command I can see –
$file file_compressed.gz
file_compressed.gz: gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT)
Do I need to put any header data while I create the compressed file with Zlib? Because when I use the inflate method instead of the GzipReader I get following error –
incorrect header check (Zlib::DataError)
./features/support/abc/abc_file.rb:69:in `inflate'
If you’re on a platform that doesn’t use
LFdelimiters, butCR+LF, you may need to open the file in binary mode for reading:This should also avoid interpreting the input stream as anything but 8-bit binary.
Be sure to open your output file the same way using
"wb"as the flag.