How are zlib, gzip and zip related? What do they have in common and how are they different?

Short form: .zip is an archive format using, usually, the Deflate compression method. The .gz gzip format is for single files, also using the Deflate compression method. Often gzip is used in combination with tar to make a compressed archive format, .tar.gz. The zlib library provides Deflate compression and decompression code for use by zip, … Read more

PowerShell script not zipping correct files

Pass the files as full paths to the Zip function, using their .FullName property (PSv3+ syntax): Zip C:\Users\Admin\Desktop\TEST.zip $Files.FullName The problem is that, in Windows PowerShell, the [System.IO.FileInfo] instances returned by Get-ChildItem situationally[1] stringify to their file names only, which is what happened in your case, so your Zip function then interpreted the $toBeZipped values … Read more

How to zip a whole folder using PHP

Code updated 2015/04/22. Zip a whole folder: // Get real path for our folder $rootPath = realpath(‘folder-to-zip’); // Initialize archive object $zip = new ZipArchive(); $zip->open(‘file.zip’, ZipArchive::CREATE | ZipArchive::OVERWRITE); // Create recursive directory iterator /** @var SplFileInfo[] $files */ $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { // … Read more

How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools?

And here are the answer(s): 1. Using “pure” batch script to zip/unzip file. It’s possible thanks to Frank Westlake’s ZIP.CMD and UNZIP.CMD(needs admin permissions and requires FSUTIL and CERTUTIL) .For Win2003 and WinXP it will require 2003 Admin Tool Pack which will install CERTUTIL. Be careful as ZIP.CMD syntax is backward : ZIP.CMD destination.zip source.file … Read more

Download multiple files as a zip-file using php

You can use the ZipArchive class to create a ZIP file and stream it to the client. Something like: $files = array(‘readme.txt’, ‘test.html’, ‘image.gif’); $zipname=”file.zip”; $zip = new ZipArchive; $zip->open($zipname, ZipArchive::CREATE); foreach ($files as $file) { $zip->addFile($file); } $zip->close(); and to stream it: header(‘Content-Type: application/zip’); header(‘Content-disposition: attachment; filename=”.$zipname); header(“Content-Length: ‘ . filesize($zipname)); readfile($zipname); The second … Read more

Appending files to a zip file with Java

In Java 7 we got Zip File System that allows adding and changing files in zip (jar, war) without manual repackaging. We can directly write to files inside zip files as in the following example. Map<String, String> env = new HashMap<>(); env.put(“create”, “true”); Path path = Paths.get(“test.zip”); URI uri = URI.create(“jar:” + path.toUri()); try (FileSystem … Read more

Unzipping files

I wrote an unzipper in Javascript. It works. It relies on Andy G.P. Na’s binary file reader and some RFC1951 inflate logic from notmasteryet. I added the ZipFile class. working example: http://cheeso.members.winisp.net/Unzip-Example.htm (dead link) The source: http://cheeso.members.winisp.net/srcview.aspx?dir=js-unzip (dead link) NB: the links are dead; I’ll find a new host soon. Included in the source is … Read more