zipfile

zipfile module giving unreliable results

只谈情不闲聊 提交于 2019-12-06 09:42:50
I made a dictionary attack on encrypted zip files, using the zipfile library. When I started using BIG dictionaries sometimes I got false positive results, i.e. password could be "wool" and "12630" was considered correct. In that case the decrypted file contained gibberish obviously. It's not a bug in my code, but in the way the zipfile library checks to see if the provided password is correct. I've managed to decrease the false positives by checking the size of the decrypted file and if it's equal to 0 consider it false and keep searching. But my problem remains, because when the file

How to compress a folder to make docx file in android?

微笑、不失礼 提交于 2019-12-06 09:41:17
I'm trying to make an Android application that can open a docx file to read, edit and save it. My idea is to extract all the xml file within the archive to a temp folder. In this folder we can edit the content of the docx in /word/document.xml . The problem is when I compress this temp folder to make a new docx file and replace the old file, inside the new docx archive the path is like /mnt/sdcard/temp/"all files xml go here" while the xml files should be in the first level. Can anybody help me to go through this? here is the method to compress the temp directory Note: dir2zip argument's value

Java NIO ZipFileSystem: “zip END header not found” while creating file system

℡╲_俬逩灬. 提交于 2019-12-06 04:56:08
问题 I'm asking this here because googling this error only gives me hits on writing a zip file, while I'm only trying to read it. I have a unit test where I'm trying to test the following production code: Map<String, String> zipProps = new HashMap<>(); URI zipUri = URI.create("jar:file:" + itemZipPath.toString()); try (FileSystem zipfiles = FileSystems.newFileSystem(zipUri, zipProps)) { // do stuff... } catch (IOException e) { // log an error } However this fails on the line containing the try:

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

喜你入骨 提交于 2019-12-06 04:48:25
问题 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 each entry. (I have looked at Apache Commons but cannot see an easy way there either). UPDATE @Rich's code seems to solve the problem, thanks QUERY why do both

Unzip buffer with Python?

佐手、 提交于 2019-12-06 00:46:11
问题 I have a buffer of bytes read from a library call and I would like to unzip the content which is a single text file. I tried with zlib , but I get this error: >>> import zlib >>> zlib.decompress(buffer) error: Error -3 while decompressing data: incorrect header check However with ZipFile it works, but I have to use a temporary file: import zipfile f = open('foo.zip', 'wb') f.write(buffer) f.close() z = ZipFile('foo.zip') z.extractall() z.close() with open('foo.txt', 'r') as f: uncompressed

Zipping files in python

懵懂的女人 提交于 2019-12-05 20:16:14
问题 My Program runs smoothly but I want my files from ftp to be zip in my local drive My Problem : Only 1 file is being zipped after calling my main() function Here's my code: main import os import upload import download import zipfile import ConfigParser import ftputil def main(): #create a folder Temp on d drive for later use path = r'D:\Temp' os.mkdir(path) #parse all the values at config.ini file config = ConfigParser.ConfigParser() config.readfp(open('config.ini')) server = config.get('main'

Download and unzip file with Python

大憨熊 提交于 2019-12-05 19:02:26
I am trying to download and open a zipped file and seem to be having trouble using a file type handle with zipfile. I'm getting the error "AttributeError: addinfourl instance has no attribute 'seek'" when running this: import zipfile import urllib2 def download(url,directory,name): webfile = urllib2.urlopen('http://www.sec.gov'+url) webfile2 = zipfile.ZipFile(webfile) content = zipfile.ZipFile.open(webfile2).read() localfile = open(directory+name, 'w') localfile.write(content) localfile.close() return() download(link.get("href"),'./fails_data', link.text) You can't seek on a urllib2.urlopen ed

Using Python to add a list of files into a zip file

↘锁芯ラ 提交于 2019-12-05 16:17:51
问题 I want to write a script to add all the ‘.py’ files into a zip file. Here is what I have: import zipfile import os working_folder = 'C:\\Python27\\' files = os.listdir(working_folder) files_py = [] for f in files: if f[-2:] == 'py': fff = working_folder + f files_py.append(fff) ZipFile = zipfile.ZipFile("zip testing.zip", "w" ) for a in files_py: ZipFile.write(a, zipfile.ZIP_DEFLATED) However it gives an error: Traceback (most recent call last): File "C:\Python27\working.py", line 19, in

Saving zip list to csv in Python

落爺英雄遲暮 提交于 2019-12-05 15:40:07
How I can write below zip list to csv file in python? [{'date': '2015/01/01 00:00', 'v': 96.5}, {'date': '2015/01/01 00:01', 'v': 97.0}, {'date': '2015/01/01 00:02', 'v': 93.75}, {'date': '2015/01/01 00:03', 'v': 96.0}, {'date': '2015/01/01 00:04', 'v': 94.5} I have this error: _csv.Error: sequence expected My code is here: import csv res = zip_list csvfile = "/home/stm/PycharmProjects/isbak_trafik/example.csv" with open(csvfile, "w") as output: writer = csv.writer(output, lineterminator='\n') writer.writerows(res) writer.writerows expects a sequence of values for writing a single row into the

Create password protected zip file Python [duplicate]

强颜欢笑 提交于 2019-12-05 13:24:48
This question already has an answer here : Python - zipfile: how to set a password for a zipfile? [duplicate] (1 answer) Closed last year . I'm using following code to create password protected zip file, from a file uploaded by user, in my Python34 application using zipFile . But when I open the zip file from windows, it doesn't ask for the password. I will be using the same password to read zip files from python later on. What am I doing wrong? Here's my code: pwdZipFilePath = uploadFilePath + "encryptedZipFiles/" filePath = uploadFilePath if not os.path.exists(pwdZipFilePath): os.makedirs