簡體   English   中英

Python文件壓縮解壓

[英]Python file zipping and unzipping

我正在使用pyminizip到 zip 和密碼保護文件。 Everyting 工作正常,但我無法理解文件的解壓縮。 我閱讀了圖書館的自述文件,但它令人困惑,解壓縮對我沒有幫助。 這是我的代碼。

拉鏈

pyminizip.compress("src_file", None, "dest.zip", "password", 5)

解壓

pyminizip.uncompress("file.zip", "password", "dest_path", int(withoutpath))

錯誤

SystemError: <built-in function uncompress> returned a result with an error set

我不知道uncompress()中的第四個參數int(withoutpath)是什么。

官方文檔說

pyminizip.compress("/srcfile/path.txt", "file_path_prefix", "/distfile/path.zip", "password", int(compress_level))

Args:
1. src file path (string)
2. src file prefix path (string) or None (path to prepend to file)
3. dst file path (string)
4. password (string) or None (to create no-password zip)
5. compress_level(int) between 1 to 9, 1 (more fast) <---> 9 (more compress) or 0 (default)

Return value:
- always returns None

pyminizip.compress_multiple([u'pyminizip.so', 'file2.txt'], [u'/path_for_file1', u'/path_for_file2'], "file.zip", "1233", 4, progress)
Args:
1. src file LIST path (list)
2. src file LIST prefix path (list) or []
3. dst file path (string)
4. password (string) or None (to create no-password zip)
5. compress_level(int) between 1 to 9, 1 (more fast) <---> 9 (more compress)
6. optional function to be called during processing which takes one argument, the count of how many files have been compressed

Return value:
- always returns None

pyminizip.uncompress("/srcfile/path.zip", "password", "/dirtoextract", int(withoutpath))
1. src file path (string)
2. password (string) or None (to unzip encrypted archives)
3. dir path to extract files or None (to extract in a specific dir or cwd)
4. withoutpath (exclude path of extracted)

Return value:
- always returns None

請幫幫我。 第四個論點真的讓我很煩,我無法在其他任何地方找到幫助。 謝謝你。

import pyminizip
pyminizip.compress("src_file", None, "dest.zip", "password", 5)
pyminizip.uncompress("file.zip", "password", "dest_path", 0)

// 代碼https://github.com/smihica/pyminizip/blob/master/src/py_miniunz.c#L227

   if ((*popt_extract_without_path)==0)
        write_filename = filename_inzip;
    else
        write_filename = filename_withoutpath;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM