How can I read a .tar.gz file with PHP?

You can do this with the PharData class: // Example: list files $archive = new PharData(‘/some/file.tar.gz’); foreach($archive as $file) { echo “$file\n”; } This even works with the phar:// stream wrapper: $list = scandir(‘phar:///some/file.tar.gz’); $fd = fopen(‘phar:///some/file.tar.gz/some/file/in/the/archive’, ‘r’); $contents = file_get_contents(‘phar:///some/file.tar.gz/some/file/in/the/archive’); If you don’t have Phar, check the PHP-only implementation, or the pecl extension.

reading tar file contents without untarring it, in python script

you can use getmembers() >>> import tarfile >>> tar = tarfile.open(“test.tar”) >>> tar.getmembers() After that, you can use extractfile() to extract the members as file object. Just an example import tarfile,os import sys os.chdir(“/tmp/foo”) tar = tarfile.open(“test.tar”) for member in tar.getmembers(): f=tar.extractfile(member) content=f.read() print “%s has %d newlines” %(member, content.count(“\n”)) print “%s has %d spaces” … Read more

How do I extract a tar file in Java?

You can do this with the Apache Commons Compress library. You can download the 1.2 version from http://mvnrepository.com/artifact/org.apache.commons/commons-compress/1.2. Here are two methods: one that unzips a file and another one that untars it. So, for a file <fileName>tar.gz, you need to first unzip it and after that untar it. Please note that the tar archive … Read more