zipfile

ASP.NET MVC returning an xls file inside an zip file

空扰寡人 提交于 2020-01-07 07:50:29
问题 I have an asp.net mvc action that returns an xls file: public void Excel(string filename) { DAOSolicitacao dao = new DAOSolicitacao(); System.Threading.Thread.Sleep(5000); var products = dao.GetSolicitacoes(); var grid = new GridView(); grid.DataSource = products; grid.DataBind(); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", filename)); Response.ContentType = "application/ms-excel"; Response.Charset = "";

zipfile.BadZipfile: Bad CRC-32 for file | Read only file

≡放荡痞女 提交于 2020-01-06 05:43:25
问题 Got a read-only file within a zip file which are password protected and I need to extract it to the /tmp directory. I get a CRC-32 error which suggests that the file would be corrupted yet I know it isn't and is in fact a read-only file. Any Suggestions? Error: Traceback (most recent call last): File "/tmp/usercode.py", line 45, in <module> zip.extractall('/tmp',pwd = "piso") File "/usr/lib64/python2.7/zipfile.py", line 1040, in extractall self.extract(zipinfo, path, pwd) File "/usr/lib64

Android 2.3 ZIP problems with general purpose flags

我是研究僧i 提交于 2020-01-05 09:04:20
问题 I made an application on Android and this application logs the activity into files. I have an option to export the files so I save the files in a .zip. If there is more than 1 file to add to the .zip, I get the following error. (general purpose flags - local: 808 hex central: 8 hex). Local and central GPFlags values don't match. This only happens with Android 2.3 and using winzip or 7zip. I can bypass this problem using windows explorer or winrar but I would like to solve the problem and not

Android 2.3 ZIP problems with general purpose flags

廉价感情. 提交于 2020-01-05 09:03:31
问题 I made an application on Android and this application logs the activity into files. I have an option to export the files so I save the files in a .zip. If there is more than 1 file to add to the .zip, I get the following error. (general purpose flags - local: 808 hex central: 8 hex). Local and central GPFlags values don't match. This only happens with Android 2.3 and using winzip or 7zip. I can bypass this problem using windows explorer or winrar but I would like to solve the problem and not

How to Extract Zip Files with non-Unicode non-Latin Filenames?

蹲街弑〆低调 提交于 2020-01-02 07:04:53
问题 Sometimes you come by Zip files with file or directory with some unrecognized characters in the names so you can't extract them. What tools do you use to extract them in properly converted filenames? 回答1: I searched the web but failed to find a good script. So out of necessity I wrote a Python script myself. Hope it comes handy for someone. Any suggestions are welcome, especially if you know this will not work in some special cases. Please don't pick on the untidy coding style. import os,sys

How can I save an edited Word document with Python?

拜拜、爱过 提交于 2020-01-01 07:22:12
问题 I am attempting to create a script which can extract the XML from a Word document, modify it, and finally save the new Word document, all using Python. Here's the code I used, which was effectively stolen from here: import zipfile import os import tempfile import shutil def getXml(docxFilename): zip = zipfile.ZipFile(open(docxFilename,"rb")) xmlString = str(zip.read("word/document.xml")) return xmlString def createNewDocx(originalDocx,xmlContent,newFilename): tmpDir = tempfile.mkdtemp() zip =

How to zip a very large file in python

拜拜、爱过 提交于 2020-01-01 06:12:26
问题 I would like to zip a couple of files that may amount to about 99 GB using python. Please what is the most efficient way to do this using the zipfile library. This is a sample code I have with gcs.open(zip_file_name, 'w', content_type=b'application/zip') as f: with zipfile.ZipFile(f, 'w') as z: for file in files: is_owner = (is_page_allowed_to_visitor(page, visitor) or (file.owner_id == visitor.id) ) if is_owner: file.show = True elif file.available_from: if file.available_from > datetime.now

How to save created Zip file to file system in python?

耗尽温柔 提交于 2019-12-31 03:41:06
问题 Using python zipfile module I created a zip file as follows: s = StringIO() zip_file = zipfile.ZipFile(s, "w") zip_file.write('/local/my_files/my_file.txt') s.seek(0) and now, I want this zip_file to be saved in my file system at path /local/my_files/ as my_file.zip . Generally to save a noraml files I used the following flow: with open(dest_file, 'w') as out_file: for line in in_file: out_file.write(line) But, I think I can't achieve saving a zipfile with this. Can any one please help me in

How can I convert byte array to ZIP file

穿精又带淫゛_ 提交于 2019-12-28 13:36:00
问题 I am trying to convert an array of bytes into a ZIP file. I got bytes using the following code: byte[] originalContentBytes= new Verification().readBytesFromAFile(new File("E://file.zip")); private byte[] readBytesFromAFile(File file) { int start = 0; int length = 1024; int offset = -1; byte[] buffer = new byte[length]; try { //convert the file content into a byte array FileInputStream fileInuptStream = new FileInputStream(file); BufferedInputStream bufferedInputStream = new

How can I convert byte array to ZIP file

孤者浪人 提交于 2019-12-28 13:35:45
问题 I am trying to convert an array of bytes into a ZIP file. I got bytes using the following code: byte[] originalContentBytes= new Verification().readBytesFromAFile(new File("E://file.zip")); private byte[] readBytesFromAFile(File file) { int start = 0; int length = 1024; int offset = -1; byte[] buffer = new byte[length]; try { //convert the file content into a byte array FileInputStream fileInuptStream = new FileInputStream(file); BufferedInputStream bufferedInputStream = new