Unzip nested zip files in python

ZipFile needs a file-like object, so you can use StringIO to turn the data you read from the nested zip into such an object. The caveat is that you’ll be loading the full (still compressed) inner zip into memory. with zipfile.ZipFile(‘foo.zip’) as z: with z.open(‘nested.zip’) as z2: z2_filedata = cStringIO.StringIO(z2.read()) with zipfile.ZipFile(z2_filedata) as nested_zip: print … Read more

Zip Stream in PHP

If your web server is running Linux, then you can do it streaming without a temp file being generated. Under Win32, you may need to use Cygwin or something similar. If you use – as the zip file name, it will compress to STDOUT. That can be redirected straight to the requester using passthru(). The … Read more

How to send zip files in the python Flask framework?

BytesIO() needs to be passed bytes data, but a ZipFile() object is not bytes-data; you actually created a file on your harddisk. You can create a ZipFile() in memory by using BytesIO() as the base: memory_file = BytesIO() with zipfile.ZipFile(memory_file, ‘w’) as zf: files = result[‘files’] for individualFile in files: data = zipfile.ZipInfo(individualFile[‘fileName’]) data.date_time = … Read more

How to zip multiple files using only .net api in c#

With the release of the .NET Framework 4.5 this is actually a lot easier now with the updates to System.IO.Compression which adds the ZipFile class. There is a good walk-through on codeguru; however, the basics are in line with the following example: using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.IO.Compression.FileSystem; namespace ZipFileCreator { public static … Read more

How do I set permissions (attributes) on a file in a ZIP file using Python’s zipfile module?

This seems to work (thanks Evan, putting it here so the line is in context): buffer = “path/filename.zip” # zip filename to write (or file-like object) name = “folder/data.txt” # name of file inside zip bytes = “blah blah blah” # contents of file inside zip zip = zipfile.ZipFile(buffer, “w”, zipfile.ZIP_DEFLATED) info = zipfile.ZipInfo(name) info.external_attr … Read more

How do you unzip very large files in python?

Here’s an outline of decompression of large files. import zipfile import zlib import os src = open( doc, “rb” ) zf = zipfile.ZipFile( src ) for m in zf.infolist(): # Examine the header print m.filename, m.header_offset, m.compress_size, repr(m.extra), repr(m.comment) src.seek( m.header_offset ) src.read( 30 ) # Good to use struct to unpack this. nm= src.read( … Read more

zip file and avoid directory structure

The zipfile.write() method takes an optional arcname argument that specifies what the name of the file should be inside the zipfile I think you need to do a modification for the destination, otherwise it will duplicate the directory. Use :arcname to avoid it. try like this: import os import zipfile def zip(src, dst): zf = … Read more