zipfile

Set permissions on a compressed file in python

I have a file test.txt that is inside a zip archive test.zip. The permissions on test.txt are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell. EDIT: Here's what I've got so far: import zipfile z = zipfile.ZipFile('test....

Why I get an Exception on opening an empty ZIP-file with java.util.zip.ZipFile?

I want to open a ZIP-file, that have no entries with java.util.zip.ZipFile. But on the constructor I get the following exception: 'java.util.zip.ZipException: error in opening zip file'. How can I open the empty ZIP? That ZIP-file is created by the commandline zip-program under linux. I simply deleted all entries from a ZIP-file. I nee...

How do I set permissions (attributes) on a file in a zip file using Python's ZipFile module?

When I extract files from a zip file created with the Python zipfile module, all the files are not writeable, read only etc. The file is being created and extracted under Linux and Python 2.5.2. As best I can tell, I need to set the ZipInfo.external_attr property for each file, but this doesn't seem to be documented anywhere I could fi...

ZipFile complains, is there a way around using the zipfile module?

Hi, I am trying to decompress some MMS messages sent to me zipped. The problem is that sometimes it works, and others not. And when it doesnt work, the python zipfile module complains and says that it is a bad zip file. But the zipfile decompresses fine using the unix unzip command. This is what ive got zippedfile = open('%stemp/tempf...

Zipping dynamic files in App Engine (Python)

Hello! Is there anyway I can zip dynamically generated content, such as a freshly rendered html template, into a zip file using zipfile? There seem to be some examples around for zipping static content, but none for zipping dynamic ones. Or, is it not possible at all? One more question: Is it possible to create a zip file with a bunch...

Python 2.6 - Upload zip file - Poster 0.4

Hi Folks, I came here via this question: http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script And by and large it's what I need, plus some additional. Besides the zipfile som additional information is needed and the POST_DATA looks something like this: POSTDATA =-----------------------------293432744627...

Randomly accessing a compressed file without using ZipFile (since ZipFile has a major bug).

I know, I know, who would want to compress or uncompressed large files in java. Completely unreasonable. For the moment suspend disbelief and assume I have a good reason for uncompressing a large zip File. Issue 1: ZipFile has a bug (bug # 6280693), sun has fixed this in java 1.6 (Mustang). The fix isn't isn't helpful as our software ne...

What would cause a zip file to not be recognized on Google App Engine's when it reads properly in my local GAE sdk

My code executes successfully when I run it locally, but when I upload it to GAE and attempt to run it throws me a BadZipfile: File is not a zip file, or ends with a comment raw_file = urllib2.urlopen(url) buffer = cStringIO.StringIO(raw_file.read()) z = zipfile.ZipFile(buffer) zipped file size is 2.5 mb unzipped size is 14 mb What i...

Confused about making a CSV file into a ZIP file in django

I have a view that takes data from my site and then makes it into a zip compressed csv file. Here is my working code sans zip: def backup_to_csv(request): response = HttpResponse(mimetype='text/csv') response['Content-Disposition'] = 'attachment; filename=backup.csv' writer = csv.writer(response, dialect='excel') #code...

What is the byte signature of a password-protected ZIP file?

I've read that ZIP files start with the following bytes: 50 4B 03 04 Reference: http://www.garykessler.net/library/file_sigs.html Question: Is there a certain sequence of bytes that indicate a ZIP file has been password-protected? ...

extracting contents of ZipFile entries when read from byte[] (Java)

I have a zip file whose contents are presented as byte[] but the original file object is not accessible. I want to read the contents of each of the entries. I am able to create a ZipInputStream from a ByteArrayInputStream of the bytes and can read the entries and their names. However I cannot see an easy way to extract the contents of ea...

detecting binary files and character encodings in zipfiles

When reading zipfiles (using Java ZipInputStream or any other library) from an unknown source is there any way of detecting which entries are "character data" (and if so the encoding) or "binary data". And, if binary, any way of determining any more information (MIME types, etc.) EDIT does the ByteOrderMark (BOM) occur in zipentries and...

Extract files with invalid characters in filename with Python

I use python's zipfile module to extract a .zip archive (Let's take this file at http://img.dafont.com/dl/?f=akvaleir for example.) f = zipfile.ZipFile('akvaleir.zip', 'r') for fileinfo in f.infolist(): print fileinfo.filename f.extract(fileinfo, '.') Its output: Akval�ir_Normal_v2007.ttf Akval�ir, La police - The Font - Fr -...

How to create a zip archive of a directory in python?

How can I create a zip archive of a directory structure in Python? ...

Python zipfile hangs when writing

I am trying to use the zipfile module in Python to create simple zip files: import zipfile files = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h') zip_file_name = 'zipfile_test.zip' zfh = zipfile.ZipFile(zip_file_name, 'w') for file in files: print 'Archiving file %s' % file zfh.write(zip_file_name) zfh.close() The files a-h are in my ...

OpenSource C library for live zip file processing

I'm looking for a C/C++ library that can open and read the contents of zipfiles (writing zipfiles isn't a strict requirement but would be nice). I want to be able to open a file, enumerate the files and then efficient read (unencrypted) data from the files in the zipfile. All the libraries I've found are all very WIN32 specific. I need...

OutOfMemory Error while trying to extract a large jar using ZipFileSet

With jdk1.5, i get an OutofMemoryError while trying to extract a reasonably large jar. However, this does not happen on jdk6. Is it because of different default heap-size/permgen settings on jdk1.5 and jdk6 or is this a bug in jdk1.5 that was fixed in jdk6? import java.io.*; import java.util.zip.*; public class UnZip { final int BUF...

jQuery download a zipfile from a button?

Quite embarrassing how much time I spend trying to get to download a zipfile from a button.... <button type='button' id='button-download'>download zipfile</button> $("#button-download").live("click", function() { $.get("http://localhost/admin/zip/002140.zip"); // doesn't work? }) I need something bullet proof here, that's why I ...

Issue in creating Zip file using glob.glob

Hi, I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files fo...

Python 2.6 does not like appending to existing archives in zip files

Hello, In some Python unit tests of a program I'm working on we use in-memory zipfiles for end to end tests. In SetUp() we create a simple zip file, but in some tests we want to overwrite some archives. For this we do "zip.writestr(archive_name, zip.read(archive_name) + new_content)". Something like import zipfile from StringIO import ...