Unzip Archive with Groovy

Maybe Groovy doesn’t have ‘native’ support for zip files, but it is still pretty trivial to work with them. I’m working with zip files and the following is some of the logic I’m using: def zipFile = new java.util.zip.ZipFile(new File(‘some.zip’)) zipFile.entries().each { println zipFile.getInputStream(it).text } You can add additional logic using a findAll method: def … Read more

How to speed up unzipping time in Java / Android?

I don’t know if unzipping on Android is slow, but copying byte for byte in a loop is surely slowing it down even more. Try using BufferedInputStream and BufferedOutputStream – it might be a bit more complicated, but in my experience it is worth it in the end. BufferedInputStream in = new BufferedInputStream(zin); BufferedOutputStream out … Read more

How to unzip files recursively in Java?

Warning, the code here is ok for trusted zip files, there’s no path validation before write which may lead to security vulnerability as described in zip-slip-vulnerability if you use it to deflate an uploaded zip file from unknown client. This solution is very similar to the previous solutions already posted, but this one recreates the … Read more

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

How to extract file from zip without maintaining directory structure in Python?

You can use zipfile.ZipFile.open: import shutil import zipfile with zipfile.ZipFile(‘/path/to/my_file.apk’) as z: with z.open(‘/res/drawable/icon.png’) as zf, open(‘temp/icon.png’, ‘wb’) as f: shutil.copyfileobj(zf, f) Or use zipfile.ZipFile.read: import zipfile with zipfile.ZipFile(‘/path/to/my_file.apk’) as z: with open(‘temp/icon.png’, ‘wb’) as f: f.write(z.read(‘/res/drawable/icon.png’))