unzip (zip, tar, tag.gz) files with ruby

To extract files from a .tar.gz file you can use the following methods from packages distributed with Ruby: require ‘rubygems/package’ require ‘zlib’ tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(‘Path/To/myfile.tar.gz’)) tar_extract.rewind # The extract has to be rewinded after every iteration tar_extract.each do |entry| puts entry.full_name puts entry.directory? puts entry.file? # puts entry.read end tar_extract.close Each entry of type Gem::Package::TarReader::Entry … Read more

Why does BCL GZipStream (with StreamReader) not reliably detect Data Errors with CRC32?

Preface .NET [4 and previous] users should not use the Microsoft-provided GZipStream or DeflateStream classes under any circumstances, unless Microsoft replaces them completely with something that works. Use the DotNetZip library instead. Update to Preface The .NET Framework 4.5 and later have fixed the compression problem, and GZipStream and DeflateStream use zlib in those versions. … Read more

Get uncompressed size of a .gz file in python

Uncompressed size is stored in the last 4 bytes of the gzip file. We can read the binary data and convert it to an int. (This will only work for files under 4GB) import struct def getuncompressedsize(filename): with open(filename, ‘rb’) as f: f.seek(-4, 2) return struct.unpack(‘I’, f.read(4))[0]

WCF GZip Compression Request/Response Processing

Thanks for your WCF tip! We’re going to be enabling IIS compression for services at my shop, and I’m hoping your solution will work. By “To make this work for Web Services” – did you mean old school SoapHttpProtocol clients? Because the SoapHttpProtocol class has a built-in EnableDecompression property, which will automatically handle the Compression … Read more

How to Compress/Decompress tar.gz files in java

I’ve written a wrapper for commons-compress called jarchivelib that makes it easy to extract or compress from and into File objects. Example code would look like this: File archive = new File(“/home/thrau/archive.tar.gz”); File destination = new File(“/home/thrau/archive/”); Archiver archiver = ArchiverFactory.createArchiver(“tar”, “gz”); archiver.extract(archive, destination);

How do you create a .gz file using PHP?

This code does the trick // Name of the file we’re compressing $file = “test.txt”; // Name of the gz file we’re creating $gzfile = “test.gz”; // Open the gz file (w9 is the highest compression) $fp = gzopen ($gzfile, ‘w9’); // Compress the file gzwrite ($fp, file_get_contents($file)); // Close the gz file and we’re … Read more