zipFly64 1.3.0__tar.gz → 1.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zipfly64-1.3.0/src/zipFly64.egg-info → zipfly64-1.3.2}/PKG-INFO +1 -1
- {zipfly64-1.3.0 → zipfly64-1.3.2}/pyproject.toml +1 -1
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/BaseFile.py +4 -2
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/Compressor.py +1 -1
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/consts.py +2 -1
- {zipfly64-1.3.0 → zipfly64-1.3.2/src/zipFly64.egg-info}/PKG-INFO +1 -1
- {zipfly64-1.3.0 → zipfly64-1.3.2}/tests/test_zipfly.py +56 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/LICENSE +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/README.md +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/setup.cfg +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/EmptyFolder.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/FilePrefetcher.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/GenFile.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/LocalFile.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/ZipBase.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/ZipFly.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly/__init__.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly64.egg-info/SOURCES.txt +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly64.egg-info/dependency_links.txt +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly64.egg-info/requires.txt +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/src/zipFly64.egg-info/top_level.txt +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/tests/test_utils.py +0 -0
- {zipfly64-1.3.0 → zipfly64-1.3.2}/tests/test_zipfly_4GB.py +0 -0
|
@@ -4,6 +4,7 @@ from collections.abc import AsyncGenerator, Generator
|
|
|
4
4
|
|
|
5
5
|
from . import consts
|
|
6
6
|
from .Compressor import Compressor
|
|
7
|
+
from .consts import DATA_DESCRIPTOR_FLAG
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
class BaseFile(ABC):
|
|
@@ -13,7 +14,7 @@ class BaseFile(ABC):
|
|
|
13
14
|
self.__offset = 0 # Offset to local file header
|
|
14
15
|
self.__crc = 0
|
|
15
16
|
self.__compression_method = compression_method
|
|
16
|
-
self.__flags =
|
|
17
|
+
self.__flags = DATA_DESCRIPTOR_FLAG # flag about using data descriptor is always on
|
|
17
18
|
self.__byte_offset_mode = False
|
|
18
19
|
if name == "":
|
|
19
20
|
raise KeyError("File name cannot be blank.")
|
|
@@ -103,7 +104,7 @@ class BaseFile(ABC):
|
|
|
103
104
|
return self.name.encode("ascii")
|
|
104
105
|
except UnicodeError:
|
|
105
106
|
self.__flags |= consts.UTF8_FLAG
|
|
106
|
-
return self.name.encode(
|
|
107
|
+
return self.name.encode()
|
|
107
108
|
|
|
108
109
|
@abstractmethod
|
|
109
110
|
def _generate_file_data(self) -> Generator[bytes, None, None]:
|
|
@@ -127,6 +128,7 @@ class BaseFile(ABC):
|
|
|
127
128
|
|
|
128
129
|
@property
|
|
129
130
|
def flags(self) -> int:
|
|
131
|
+
_ = self.file_path_bytes # trigger to set utf8 flag if needed
|
|
130
132
|
return self.__flags
|
|
131
133
|
|
|
132
134
|
@property
|
|
@@ -4,7 +4,8 @@ import struct
|
|
|
4
4
|
# ZIP CONSTANTS
|
|
5
5
|
ZIP64_VERSION = 45
|
|
6
6
|
VERSION_MADE_BY = 0x0A45 # Windows and ZIP version 45
|
|
7
|
-
UTF8_FLAG =
|
|
7
|
+
UTF8_FLAG = 0x0800 # utf-8 filename encoding flag
|
|
8
|
+
DATA_DESCRIPTOR_FLAG = 0x08 # flag that signalises that a data descriptor is used
|
|
8
9
|
|
|
9
10
|
# ZIP COMPRESSION METHODS
|
|
10
11
|
NO_COMPRESSION = 0
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Run tests of ZipFly."""
|
|
2
2
|
import re
|
|
3
|
+
import struct
|
|
3
4
|
import time
|
|
4
5
|
import zipfile
|
|
5
6
|
import zlib
|
|
@@ -654,3 +655,58 @@ def test_EmptyFolder_creates_empty_directory(tmp_path):
|
|
|
654
655
|
with zfp.open(folder_name) as folder_file:
|
|
655
656
|
content = folder_file.read()
|
|
656
657
|
assert content == b""
|
|
658
|
+
|
|
659
|
+
def _read_local_flags(data, offset):
|
|
660
|
+
return struct.unpack_from("<H", data, offset + 6)[0]
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def _read_central_flags(data, offset):
|
|
664
|
+
return struct.unpack_from("<H", data, offset + 8)[0]
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
def test_non_ascii_file_names_utf8_flag(tmp_path):
|
|
668
|
+
file_path = tmp_path / "input.bin"
|
|
669
|
+
file_path.write_bytes(lorem_ipsum)
|
|
670
|
+
|
|
671
|
+
files = [
|
|
672
|
+
LocalFile(file_path=file_path, name="zażółć.txt"),
|
|
673
|
+
LocalFile(file_path=file_path, name="файл.txt"),
|
|
674
|
+
LocalFile(file_path=file_path, name="αρχείο.txt"),
|
|
675
|
+
LocalFile(file_path=file_path, name="ファイル.txt"),
|
|
676
|
+
LocalFile(file_path=file_path, name="文件.txt"),
|
|
677
|
+
]
|
|
678
|
+
|
|
679
|
+
zip_path = tmp_path / "non_ascii_flags.zip"
|
|
680
|
+
zipfly = ZipFly(files)
|
|
681
|
+
|
|
682
|
+
with open(zip_path, "wb") as f:
|
|
683
|
+
for chunk in zipfly.stream():
|
|
684
|
+
f.write(chunk)
|
|
685
|
+
|
|
686
|
+
data = zip_path.read_bytes()
|
|
687
|
+
|
|
688
|
+
UTF8_FLAG = 0x0800
|
|
689
|
+
|
|
690
|
+
# --- scan local headers ---
|
|
691
|
+
offset = 0
|
|
692
|
+
while True:
|
|
693
|
+
sig = data.find(b"PK\x03\x04", offset)
|
|
694
|
+
if sig == -1:
|
|
695
|
+
break
|
|
696
|
+
|
|
697
|
+
flags = _read_local_flags(data, sig)
|
|
698
|
+
assert flags & UTF8_FLAG, f"UTF-8 flag missing in local header at {sig}"
|
|
699
|
+
|
|
700
|
+
offset = sig + 4
|
|
701
|
+
|
|
702
|
+
# --- scan central directory ---
|
|
703
|
+
offset = 0
|
|
704
|
+
while True:
|
|
705
|
+
sig = data.find(b"PK\x01\x02", offset)
|
|
706
|
+
if sig == -1:
|
|
707
|
+
break
|
|
708
|
+
|
|
709
|
+
flags = _read_central_flags(data, sig)
|
|
710
|
+
assert flags & UTF8_FLAG, f"UTF-8 flag missing in central dir at {sig}"
|
|
711
|
+
|
|
712
|
+
offset = sig + 4
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|