zipindex 1.0.0__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.
@@ -0,0 +1,16 @@
1
+
2
+ # Resources
3
+ *.png
4
+
5
+
6
+ # Project
7
+ .spyproject/
8
+ .venv
9
+ dist/
10
+ uv.lock
11
+ .python-version
12
+ .pypirc
13
+
14
+ # Python Artifacts
15
+ *.egg-info
16
+ __pycache__/
zipindex-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trent Oberlander
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: zipindex
3
+ Version: 1.0.0
4
+ Summary: Simple indexing for working with files inside zipfiles
5
+ Project-URL: homepage, https://www.github.com/ResoluteVinculum/ZipIndex
6
+ Project-URL: issues, https://www.github.com/ResoluteVinculum/ZipIndex/issues
7
+ Author-email: Trent Oberlander <trentoberlander@gmail.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Trent Oberlander
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: files
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: Programming Language :: Python :: 3
33
+ Requires-Python: >=3.11
34
+ Description-Content-Type: text/markdown
35
+
36
+ # ZipIndex
37
+
38
+ Simple, pure-python object package for dealing with many files inside of
39
+ zipfiles.
40
+
41
+ # Example Usage
42
+ ```python
43
+ from zipindex import ZipIndex
44
+
45
+ # Single Instance
46
+ inst = ZipIndex(zipfile_path="...", member_name="...")
47
+
48
+ # Simple Factory
49
+ members: dict[str, ZipIndex] = ZipIndex.factory(zipfile_path="...")
50
+
51
+ # Categorical Factory
52
+ categories: dict[str, ZipIndex] = ZipIndex.categorical_factory(zipfile_path="...", categories={"empty" : {0 : b""}})
53
+
54
+ # Use
55
+ with inst.open() as fid:
56
+ data = fid.read()
57
+
58
+ ```
@@ -0,0 +1,23 @@
1
+ # ZipIndex
2
+
3
+ Simple, pure-python object package for dealing with many files inside of
4
+ zipfiles.
5
+
6
+ # Example Usage
7
+ ```python
8
+ from zipindex import ZipIndex
9
+
10
+ # Single Instance
11
+ inst = ZipIndex(zipfile_path="...", member_name="...")
12
+
13
+ # Simple Factory
14
+ members: dict[str, ZipIndex] = ZipIndex.factory(zipfile_path="...")
15
+
16
+ # Categorical Factory
17
+ categories: dict[str, ZipIndex] = ZipIndex.categorical_factory(zipfile_path="...", categories={"empty" : {0 : b""}})
18
+
19
+ # Use
20
+ with inst.open() as fid:
21
+ data = fid.read()
22
+
23
+ ```
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["hatchling", "uv-dynamic-versioning"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "zipindex"
7
+ description = "Simple indexing for working with files inside zipfiles"
8
+ readme = "README.md"
9
+ authors = [
10
+ { name="Trent Oberlander", email="trentoberlander@gmail.com"}
11
+ ]
12
+ requires-python = ">=3.11"
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ license = { file = "LICENSE" }
18
+ keywords = ["files"]
19
+ dependencies = [
20
+ ]
21
+ dynamic = ["version"]
22
+
23
+ [tool.hatch.build]
24
+ include = [
25
+ ]
26
+
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["zipindex"]
30
+
31
+ [tool.hatch.build.targets.sdist]
32
+ packages = ["zipindex"]
33
+
34
+
35
+ [tool.hatch.version]
36
+ source = "uv-dynamic-versioning"
37
+
38
+ [tool.uv-dynamic-versioning]
39
+ fallback-version = "0.1.0"
40
+
41
+ [project.urls]
42
+ homepage = "https://www.github.com/ResoluteVinculum/ZipIndex"
43
+ issues = "https://www.github.com/ResoluteVinculum/ZipIndex/issues"
@@ -0,0 +1,2 @@
1
+ #
2
+ from zipindex.indexer import ZipIndex
@@ -0,0 +1,110 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Simple addition to zipfile options that allows for intuitive control over
4
+ zipfile internal uses
5
+
6
+ """
7
+
8
+ import zipfile
9
+ from typing import Self, Iterable
10
+ import os
11
+ from functools import partial
12
+ import re
13
+
14
+
15
+ def member_endswith(member: zipfile.ZipInfo,
16
+ match_key: str) -> bool:
17
+ return member.filename.endswith(match_key)
18
+
19
+ class ZipIndex:
20
+
21
+ def __repr__(self) -> str:
22
+ return (f"ZipIndex(zipfile_path={self.zipfile_path}, "
23
+ f"member_name={self.member_name})")
24
+
25
+ def __init__(self,
26
+ zipfile_path: str,
27
+ member_name: str) -> Self:
28
+
29
+ self.zipfile_path = zipfile_path
30
+ self.member_name = member_name
31
+
32
+ def open(self, mode:str = 'r') -> os.PathLike:
33
+ self.zf = zipfile.ZipFile(self.zipfile_path, mode)
34
+ matched_file = max(self.zf.filelist,
35
+ key=partial(member_endswith,
36
+ match_key=self.member_name))
37
+ self.fid = self.zf.open(matched_file, mode)
38
+ return self.fid
39
+
40
+ def suffix(self):
41
+ m = re.match(r"^.*(\.\w+)$", self.member_name)
42
+ if m:
43
+ return m.group(1)
44
+ return ""
45
+
46
+
47
+ def __enter__(self) -> os.PathLike:
48
+ return self.open()
49
+
50
+ def __exit__(self, etype, e, tb) -> None:
51
+ self.fid.close()
52
+ self.zf.close()
53
+ return None
54
+
55
+
56
+ @classmethod
57
+ def factory(cls, zipfile_path: str) -> dict[str, Self]:
58
+ with zipfile.ZipFile(zipfile_path, 'r') as zf:
59
+ output = {
60
+ member.filename : cls(zipfile_path,
61
+ member.filename.split("/")[-1])
62
+ for member in zf.filelist
63
+ if not member.filename.endswith("/")}
64
+ return output
65
+
66
+ @classmethod
67
+ def categorical_factory(cls,
68
+ zipfile_path: str,
69
+ categories: dict[str, Iterable[dict[int, bytes]]]) -> dict[str, tuple[Self]]:
70
+ """
71
+ Provides a factory for categorizing internal files in a zipfile.ZipFile
72
+ Must match all conditions of at least one category to be included in
73
+ the output.
74
+
75
+ Parameters
76
+ ----------
77
+ zipfile_path : str
78
+ Path to the zipfile.
79
+ categories : dict[str, Iterable[dict[int, bytes]]]
80
+ Dictionary definition of bytes-wise matching for type detection.
81
+ Ex: {"empty" : [{0: b""}]}
82
+ Returns
83
+ -------
84
+ dict[str, tuple[Self]]
85
+ {category : tuple[ZipIndex]}.
86
+
87
+ """
88
+ assert categories
89
+ output = {cat: [] for cat in categories}
90
+ with zipfile.ZipFile(zipfile_path, 'r') as zf:
91
+ for category, definition in categories.items():
92
+ for member in zf.filelist:
93
+ if member.filename.endswith("/"): continue
94
+ with zf.open(member, 'r') as fid:
95
+ matched = []
96
+ for position, condition in definition.items():
97
+ fid.seek(position, 0)
98
+ if len(condition) == 0:
99
+ b = fid.read()
100
+ else:
101
+ b = fid.read(len(condition))
102
+ matched.append((b == condition))
103
+ if all(matched):
104
+ output[category].append(cls(zipfile_path,
105
+ member.filename.split("/")[-1]))
106
+ return output
107
+
108
+ idx = ZipIndex.categorical_factory(zipfile_path='C:/dev/data.zip',
109
+ categories={"empty": {0: b""},
110
+ "bin" : {0: b"BIN"}})