zip

Overwrite contents of ZipArchiveEntry

二次信任 提交于 2020-07-05 09:17:05
问题 How can I overwrite contents of a ZipArchiveEntry ? Following code using StreamWriter with StringBuilder fails if the new file contents are shorter than the original ones, for example: using System.IO.Compression; //... using (var archive = ZipFile.Open("Test.zip", ZipArchiveMode.Update)) { StringBuilder document; var entry = archive.GetEntry("foo.txt");//entry contents "foobar123" using (StreamReader reader = new StreamReader(entry.Open())) { document = new StringBuilder(reader.ReadToEnd());

Deflate - Inflate errors. Causing “incorrect header check” errors

拜拜、爱过 提交于 2020-06-29 06:51:20
问题 I am working on implementing a SAMLSLO through HTTP-REDIRECT binding mechanism. Using deflate-inflate tools gives me a DataFormatException with incorrect header check. I tried this as a stand-alone. Though I did not get DataFormatException here I observed the whole message is not being returned. import java.io.UnsupportedEncodingException; import java.util.logging.Level; import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; public class

Python: zip all folders in directory

安稳与你 提交于 2020-06-26 06:24:21
问题 If I know the path of the directory, how can I zip separately all the folders in it? I tried something, but since I don't fully understand how the os module works, there's not much I can do. import os, zipfile directory_path = str(raw_input()) for folder in os.listdir(directory_path): zip_file = zipfile.ZipFile(folder + '.zip', 'w') for root, dirs, files in os.walk(directory_path+'/'+folder): for file in files: zip_file.write(os.path.join(root, file),file) zip_file.close() The problem is that

Merge multiple zip files into a single zip file in Python

喜你入骨 提交于 2020-06-25 07:40:26
问题 I have multiple zip files that have the same structure -- they contain XML files at the root level. All files in each zip file are unique (no duplicates across the zip files). I need to combine all of the XML files from all of the zip files into a single zip file (with the same structure as the original zip files). Suggestions for how to best go about doing this? Thanks. 回答1: This is the shortest version I could come up with: >>> import zipfile as z >>> z1 = z.ZipFile('z1.zip', 'a') >>> z2 =

Python zip multiple directories into one zip file

帅比萌擦擦* 提交于 2020-06-22 19:19:30
问题 I have a top directory ds237 which has multiple sub-directories under it as below: ds237/ ├── dataset_description.json ├── derivatives ├── sub-01 ├── sub-02 ├── sub-03 ├── sub-04 ├── sub-05 ├── sub-06 ├── sub-07 ├── sub-08 ├── sub-09 ├── sub-10 ├── sub-11 ├── sub-12 ├── sub-13 ├── sub-21 ├── sub-22 ├── sub-23 ├── sub-24 ├── sub-25 ├── sub-26 ├── sub-27 ├── sub-28 ├── sub-29 I am trying to create multiple zip files(with proper zip names) from ds237 as per size of the zip files. sub01-01.zip:

How to modify a single file inside a very large zip without re-writing the entire zip?

≯℡__Kan透↙ 提交于 2020-06-16 03:35:08
问题 I have large zip files that contain huge files. There are "metadata" text files within the zip archives that need to be modified. However, it is not possible to extract the entire zip and re-compress it. I need to locate the target text file inside the zip, edit it, and possibly append the change to the zip file. The file name of the text file is always the same, so it can be hard-coded. Is this possible? Is there a better way? 回答1: There are two approaches. First, if you're just trying to

Why is the import of `*.so` files from ZIP files disallowed in Python?

China☆狼群 提交于 2020-06-12 12:57:13
问题 Why is the import of *.so files from ZIP files disallowed in Python? The documentation (https://docs.python.org/2/library/zipimport.html) is very clear: Any files may be present in the ZIP archive, but only files .py and .py[co] are available for import. ZIP import of dynamic modules (.pyd, .so) is disallowed. But the documentation doesn't name any reason for this strange limitation. Is is because importing from ZIP files is generally discouraged in Python? Or is it because of security

Pandas list comprehension tuple from dataframe

孤人 提交于 2020-06-08 20:01:21
问题 This is just a nitpicking syntactic question... I have a dataframe, and I want to use list comprehension to evaluate a function using lots of columns. I know I can do this df['result_col'] = [some_func(*var) for var in zip(df['col_1'], df['col_2'],... ,df['col_n'])] I would like to do something like this df['result_col'] = [some_func(*var) for var in zip(df[['col_1', 'col_2',... ,'col_n']])] i.e. not having to write df n times. I cannot for the life of me figure out the syntax. 回答1: this

Extract Specific Filetypes From Multiple Zips to one Folder in Powershell

心已入冬 提交于 2020-06-06 08:19:22
问题 I have Several zip files that Contain multiple filetypes. The ONLY ones I am interested in are the .txt files. I need to extract the .txt files only and place them in a folder of their own, ignoring all other file types in the zips files. All the zip files are in the same folder. Example -foo.zip --1.aaa --2.bbb --3.ccc --4.txt -foo2.zip --5.aaa --6.bbb --7.ccc --8.txt I want to have 4.txt and 8.txt extracted to another folder. I can't for the life of my figure it out and spent ages looking,

How to parse a zipped file completely from RAM?

柔情痞子 提交于 2020-05-29 06:01:06
问题 Background I need to parse some zip files of various types (getting some inner files content for one purpose or another, including getting their names). Some of the files are not reachable via file-path, as Android has Uri to reach them, and as sometimes the zip file is inside another zip file. With the push to use SAF, it's even less possible to use file-path in some cases. For this, we have 2 main ways to handle: ZipFile class and ZipInputStream class. The problem When we have a file-path,