zipfile

Java: `A` Archive attribute missing while creating zip programmatically

谁说我不能喝 提交于 2019-12-02 06:42:14
问题 We are dealing with the decompression libraries/utility that uses attribute to check for the presence of directories/files within the zip. Problem is that we are not able to set archive bit for a zip while creation. When we create zip programmatically, it wash out previous attributes as well. We will try to set archive bit with below mentioned steps but not getting desired result so far: 1. Parse each zip entry and getExtra byte[]. 2. Use Int value=32 and perform bitwise 'OR' operation. 3.

Python - zipfile: how to set a password for a zipfile? [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-02 06:07:51
问题 This question already has answers here : Python code to create a password encrypted zip file? [duplicate] (5 answers) Closed 2 years ago . I have a zipfile in (sav.zip) and I'm trying to set a Password for it: zf = zipfile.ZipFile("sav.zip") zf.setpassword("1234") but... I get a TypeError: expected Bytes, got str Where's my mistake? 回答1: It is not mentioned in the documentation, but on Python 3, the password should be bytes , not str . So: zf.setpassword(b"1234") Note that the password is

How to download a ZipFile from a dotnet core webapi?

旧巷老猫 提交于 2019-12-02 05:33:57
I am trying to download a zip file from a dotnet core web api action, but I can't make it work. I tried calling the action via POSTMAN and my Aurelia Http Fetch Client. I am able to create the ZipFile like I want it and store it on the system, but can't fix it so it returns the zipfile via the api. Use-case: User selects a couple of picture collections and clicks the download button. The ids of the picture collections gets send to the api and a zipfile is created which contains a directory for every picture collection which holds the pictures. That zipfile is returned to the user so he/she can

Extract zip to memory, parse contents

时间秒杀一切 提交于 2019-12-02 03:51:36
I want to read the contents of a zip file into memory rather than extracting them to disc, find a particular file in the archive, open the file and extract a line from it. Can a StringIO instance be opened and parsed? Suggestions? Thanks in advance. zfile = ZipFile('name.zip', 'r') for name in zfile.namelist(): if fnmatch.fnmatch(name, '*_readme.xml'): name = StringIO.StringIO() print name # prints StringIO instances open(name, 'r') # IO Error: No such file or directory... I found a few similar posts, but none that seem to address this issue: Extracting a zipfile to memory? IMO just using read

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

三世轮回 提交于 2019-12-02 02:27:21
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 getting this done. zip_file = zipfile.ZipFile("/local/my_files/my_file.zip", "w") zip_file.write('

Python - zipfile: how to set a password for a zipfile? [duplicate]

对着背影说爱祢 提交于 2019-12-02 02:09:35
This question already has an answer here: Python code to create a password encrypted zip file? [duplicate] 5 answers I have a zipfile in (sav.zip) and I'm trying to set a Password for it: zf = zipfile.ZipFile("sav.zip") zf.setpassword("1234") but... I get a TypeError: expected Bytes, got str Where's my mistake? It is not mentioned in the documentation, but on Python 3, the password should be bytes , not str . So: zf.setpassword(b"1234") Note that the password is only used for reading , not writing! See the docstring for ZipFile.open in Python 3. The ZipFile class can read "pkzip 2.0"

Python unzip AES-128 encrypted file

霸气de小男生 提交于 2019-12-02 00:31:06
问题 Is there a way to decompress an AES-128 encrypte file directly with python, since ZipFile throws a Bad Password error. If i use 7zip it works, so the password is correct, but then again 7zip needs to be installed as a dependency. What i tried: from ZipFile import ZipFile zip = ZipFile('test.zip') zip.extractall(pwd='password') This throws the Bad Password exception. Checking the file with 7zip 7z l -slt test.zip This returns: Encrypted = + Method = pkAES-128 Deflate 回答1: The zipfile module

Python zipfile dosen't release zip file

旧时模样 提交于 2019-12-01 22:37:32
I'm trying to use zipfile library on windows 8.1 and python 2.7.9. I just want to remove library.zip after zipfile.open() but os.remove() throws "WindowsError [Error 32]" and it seems zipfile doesn't release the zip file out of with block. WindowsError 32 means "The process cannot access the file because it is being used by another process." So, how can I remove this library.zip file? code: import os import zipfile as z dirs = os.listdir('build/') bSystemStr = dirs[0] print("[-] Merging library.zip...") with z.ZipFile('build/' + bSystemStr + '/library.zip', 'a') as z1: with z.ZipFile('build

Python zipfile dosen't release zip file

China☆狼群 提交于 2019-12-01 22:32:34
问题 I'm trying to use zipfile library on windows 8.1 and python 2.7.9. I just want to remove library.zip after zipfile.open() but os.remove() throws "WindowsError [Error 32]" and it seems zipfile doesn't release the zip file out of with block. WindowsError 32 means "The process cannot access the file because it is being used by another process." So, how can I remove this library.zip file? code: import os import zipfile as z dirs = os.listdir('build/') bSystemStr = dirs[0] print("[-] Merging

How to return multiple files in HttpResponse Django

蹲街弑〆低调 提交于 2019-12-01 22:11:20
I have been wracking my brains in this problem. Is there a way in django to serve multiple files from a single HttpResponse? I have a scenario where i am looping through a list of json and want to return all those as file form my admin view. class CompanyAdmin(admin.ModelAdmin): form = CompanyAdminForm actions = ['export_company_setup'] def export_company_setup(self, request, queryset): update_count = 0 error_count = 0 company_json_list = [] response_file_list = [] for pb in queryset.all(): try: # get_company_json_data takes id and returns json for the company. company_json_list.append(get