zipfile

End of Central Directory record could not be found

喜夏-厌秋 提交于 2019-11-27 14:56:54
I am downloading a zip file using c# program and I get the error at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory() at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen) at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding) at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding) at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileN ame, String destinationDirectoryName, Encoding

How do you read a file inside a zip file as text, not bytes?

对着背影说爱祢 提交于 2019-11-27 14:23:46
问题 A simple program for reading a CSV file inside a zip file works in Python 2.7, but not in Python 3.2 $ cat test_zip_file_py3k.py import csv, sys, zipfile zip_file = zipfile.ZipFile(sys.argv[1]) items_file = zip_file.open('items.csv', 'rU') for row in csv.DictReader(items_file): pass $ python2.7 test_zip_file_py3k.py ~/data.zip $ python3.2 test_zip_file_py3k.py ~/data.zip Traceback (most recent call last): File "test_zip_file_py3k.py", line 8, in <module> for row in csv.DictReader(items_file):

Compress a single file using C#

随声附和 提交于 2019-11-27 12:49:18
问题 I am using .NET 4.5, and the ZipFile class works great if I am trying to zip up an entire directory with "CreateFromDirectory". However, I only want to zip up one file in the directory. I tried pointing to a specific file (folder\data.txt), but that doesn't work. I considered the ZipArchive class since it has a "CreateEntryFromFile" method, but it seems this only allows you to create an entry into an existing file. Is there no way to simply zip up one file without creating an empty zipfile

Extract files from zip without keeping the structure using python ZipFile?

允我心安 提交于 2019-11-27 07:45:59
I try to extract all files from .zip containing subfolders in one folder. I want all the files from subfolders extract in only one folder without keeping the original structure. At the moment, I extract all, move the files to a folder, then remove previous subfolders. The files with same names are overwrited. Is it possible to do it before writing files? Here is a structure for example: my_zip/file1.txt my_zip/dir1/file2.txt my_zip/dir1/dir2/file3.txt my_zip/dir3/file4.txt At the end I whish this: my_dir/file1.txt my_dir/file2.txt my_dir/file3.txt my_dir/file4.txt What can I add to this code ?

Extracting a zipfile to memory?

梦想与她 提交于 2019-11-27 07:34:05
How do I extract a zip to memory? My attempt (returning None on .getvalue() ): from zipfile import ZipFile from StringIO import StringIO def extract_zip(input_zip): return StringIO(ZipFile(input_zip).extractall()) mata extractall extracts to the file system, so you won't get what you want. To extract a file in memory, use the ZipFile.read() method. If you really need the full content in memory, you could do something like: def extract_zip(input_zip): input_zip=ZipFile(input_zip) return {name: input_zip.read(name) for name in input_zip.namelist()} Deviacium Frequently working with in-memory

End of Central Directory record could not be found

99封情书 提交于 2019-11-27 05:54:05
问题 I am downloading a zip file using c# program and I get the error at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory() at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen) at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding) at System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding) at System.IO.Compression.ZipFile

How to send zip files in the python Flask framework?

孤街醉人 提交于 2019-11-27 04:37:22
I have a flask server that grabs binary data for several different files from a database and puts them into a python 'zipfile' object. I want to send the generated zip file with my code using flask's "send_file" method. I was originally able to send non-zip files successfully by using the BytesIO(bin) as the first argument to send_file, but for some reason I can't do the same thing with my generated zip file. It gives the error: 'ZipFile' does not have the buffer interface. How do I send this zip file object to the user with Flask? This is my code: @app.route("/getcaps",methods=['GET','POST'])

python/zip: How to eliminate absolute path in zip archive if absolute paths for files are provided?

纵饮孤独 提交于 2019-11-27 03:48:53
I have two files in two different directories, one is '/home/test/first/first.pdf' , the other is '/home/text/second/second.pdf' . I use following code to compress them: import zipfile, StringIO buffer = StringIO.StringIO() first_path = '/home/test/first/first.pdf' second_path = '/home/text/second/second.pdf' zip = zipfile.ZipFile(buffer, 'w') zip.write(first_path) zip.write(second_path) zip.close() After I open the zip file that I created, I have a home folder in it, then there are two sub-folders in it, first and second , then the pdf files. I don't know how to include only two pdf files

Opening downloaded zip file creates cpgz file?

和自甴很熟 提交于 2019-11-27 03:30:10
问题 If I make the url for a zip file the href of a link and click the link, my zip file gets downloaded and opening it gets the contents as I expect. Here's that HTML: <a href="http://mysite.com/uploads/my-archive.zip">download zip</a> The problem is I'd like the link to point to my application such that I could determine whether the user is authorized to access this zip file. so I'd like my HTML to be this: <a href="/canDownload">download zip</a> and my PHP for the /canDownload page: //business

how to download a zip file

喜欢而已 提交于 2019-11-27 01:50:27
问题 I am trying to download a zip file from my web api controller. It is returning the file but I am getting a message the zipfile is invalid when i try to open. I have seen other posts about this and the response was adding the responseType: 'arraybuffer'. Still isn't working for me. I'm not getting any errors in the console either. var model = $scope.selection; var res = $http.post('/api/apiZipPipeLine/', model) res.success(function (response, status, headers, config) { saveAs(new Blob(