zipremove 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Danny Lin
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,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: zipremove
3
+ Version: 0.1.0
4
+ Summary: Extend `zipfile` with `remove`-related functionalities
5
+ Home-page: https://github.com/danny0838/zipremove
6
+ Author: Danny Lin
7
+ Author-email: danny0838@gmail.com
8
+ License: MIT
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: System :: Archiving :: Compression
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: ~=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE.txt
23
+ Provides-Extra: dev
24
+ Requires-Dist: tox>=4.0; extra == "dev"
25
+ Requires-Dist: build; extra == "dev"
26
+ Requires-Dist: twine>=4.0; extra == "dev"
27
+ Requires-Dist: flake8>=5.0; extra == "dev"
28
+ Requires-Dist: flake8-comprehensions>=3.12; extra == "dev"
29
+ Requires-Dist: flake8-bugbear>=22.0; extra == "dev"
30
+ Requires-Dist: flake8-isort>=6.0; extra == "dev"
31
+ Requires-Dist: isort>=5.5; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ This package extends `zipfile` with `remove`-related functionalities.
35
+
36
+ ## API
37
+
38
+ * `ZipFile.remove(zinfo_or_arcname)`
39
+
40
+ Removes a member from the archive. *zinfo_or_arcname* may be the full path
41
+ of the member or a `ZipInfo` instance.
42
+
43
+ If multiple members share the same full path, only one is removed when
44
+ a path is provided.
45
+
46
+ This does not physically remove the local file entry from the archive;
47
+ the ZIP file size remains unchanged. Call `ZipFile.repack` afterwards
48
+ to reclaim space.
49
+
50
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.
51
+
52
+ Returns the removed `ZipInfo` instance.
53
+
54
+ Calling `remove` on a closed ZipFile will raise a `ValueError`.
55
+
56
+ * `ZipFile.repack(removed=None, *, strict_descriptor=False[, chunk_size])`
57
+
58
+ Rewrites the archive to remove stale local file entries, shrinking the ZIP
59
+ file size.
60
+
61
+ If *removed* is provided, it must be a sequence of `ZipInfo` objects
62
+ representing removed entries; only their corresponding local file entries
63
+ will be removed.
64
+
65
+ If *removed* is not provided, local file entries no longer referenced in the
66
+ central directory will be removed. The algorithm assumes that local file
67
+ entries are stored consecutively:
68
+
69
+ 1. Data before the first referenced entry is removed only when it appears to
70
+ be a sequence of consecutive entries with no extra following bytes; extra
71
+ preceeding bytes are preserved.
72
+ 2. Data between referenced entries is removed only when it appears to
73
+ be a sequence of consecutive entries with no extra preceding bytes; extra
74
+ following bytes are preserved.
75
+
76
+ ``strict_descriptor=True`` can be provided to skip the slower scan for an
77
+ unsigned data descriptor (deprecated in the latest ZIP specification and is
78
+ only used by legacy tools) when checking for bytes resembling a valid local
79
+ file entry. This improves performance, but may cause some stale local file
80
+ entries to be preserved, as any entry using an unsigned descriptor cannot
81
+ be detected.
82
+
83
+ *chunk_size* may be specified to control the buffer size when moving
84
+ entry data (default is 1 MiB).
85
+
86
+ The archive must be opened with mode ``'a'``.
87
+
88
+ Calling `repack` on a closed ZipFile will raise a `ValueError`.
89
+
90
+ * `ZipFile.copy(zinfo_or_arcname, new_arcname[, chunk_size])`
91
+
92
+ Copies a member *zinfo_or_arcname* to *new_arcname* in the archive.
93
+ *zinfo_or_arcname* may be the full path of the member or a `ZipInfo`
94
+ instance.
95
+
96
+ *chunk_size* may be specified to control the buffer size when copying
97
+ entry data (default is 1 MiB).
98
+
99
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``, and the
100
+ underlying stream must be seekable.
101
+
102
+ Returns the original version of the copied `ZipInfo` instance.
103
+
104
+ Calling `copy` on a closed ZipFile will raise a `ValueError`.
105
+
106
+
107
+ ## Examples
108
+
109
+ ### Remove files and reclaim space
110
+
111
+ ```python
112
+ import os
113
+ import zipremove as zipfile
114
+
115
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
116
+ zh.writestr('file1', 'content1')
117
+ zh.writestr('file2', 'content2')
118
+ zh.writestr('file3', 'content3')
119
+ zh.writestr('file4', 'content4')
120
+
121
+ print(os.path.getsize('archive.zip')) # 398
122
+
123
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
124
+ zh.remove('file1')
125
+ zh.remove('file2')
126
+ zh.remove('file3')
127
+ zh.repack()
128
+
129
+ print(os.path.getsize('archive.zip')) # 116
130
+ ```
131
+
132
+ ### Remove files under a directory and reclaim space
133
+
134
+ ```python
135
+ import os
136
+ import zipremove as zipfile
137
+
138
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
139
+ zh.writestr('file0', 'content0')
140
+ zh.writestr('folder/file1', 'content1')
141
+ zh.writestr('folder/file2', 'content2')
142
+ zh.writestr('folder/file3', 'content3')
143
+
144
+ print(os.path.getsize('archive.zip')) # 440
145
+
146
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
147
+ zinfos = [zh.remove(n) for n in zh.namelist() if n.startswith('folder/')]
148
+ zh.repack(zinfos)
149
+
150
+ print(os.path.getsize('archive.zip')) # 116
151
+ ```
152
+
153
+ ### Rename files under a directory and reclaim space
154
+
155
+ ```python
156
+ import os
157
+ import zipremove as zipfile
158
+
159
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
160
+ zh.writestr('file0', 'content0')
161
+ zh.writestr('folder1/file1', 'content1')
162
+ zh.writestr('folder1/file2', 'content2')
163
+ zh.writestr('folder1/file3', 'content3')
164
+
165
+ print(os.path.getsize('archive.zip')) # 446
166
+
167
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
168
+ for n in zh.namelist():
169
+ if n.startswith('folder1/'):
170
+ n2 = 'folder2/' + n[len('folder1/'):]
171
+ zh.copy(n, n2)
172
+ zh.remove(n)
173
+ zh.repack()
174
+
175
+ print(os.path.getsize('archive.zip')) # 446
176
+ ```
@@ -0,0 +1,143 @@
1
+ This package extends `zipfile` with `remove`-related functionalities.
2
+
3
+ ## API
4
+
5
+ * `ZipFile.remove(zinfo_or_arcname)`
6
+
7
+ Removes a member from the archive. *zinfo_or_arcname* may be the full path
8
+ of the member or a `ZipInfo` instance.
9
+
10
+ If multiple members share the same full path, only one is removed when
11
+ a path is provided.
12
+
13
+ This does not physically remove the local file entry from the archive;
14
+ the ZIP file size remains unchanged. Call `ZipFile.repack` afterwards
15
+ to reclaim space.
16
+
17
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.
18
+
19
+ Returns the removed `ZipInfo` instance.
20
+
21
+ Calling `remove` on a closed ZipFile will raise a `ValueError`.
22
+
23
+ * `ZipFile.repack(removed=None, *, strict_descriptor=False[, chunk_size])`
24
+
25
+ Rewrites the archive to remove stale local file entries, shrinking the ZIP
26
+ file size.
27
+
28
+ If *removed* is provided, it must be a sequence of `ZipInfo` objects
29
+ representing removed entries; only their corresponding local file entries
30
+ will be removed.
31
+
32
+ If *removed* is not provided, local file entries no longer referenced in the
33
+ central directory will be removed. The algorithm assumes that local file
34
+ entries are stored consecutively:
35
+
36
+ 1. Data before the first referenced entry is removed only when it appears to
37
+ be a sequence of consecutive entries with no extra following bytes; extra
38
+ preceeding bytes are preserved.
39
+ 2. Data between referenced entries is removed only when it appears to
40
+ be a sequence of consecutive entries with no extra preceding bytes; extra
41
+ following bytes are preserved.
42
+
43
+ ``strict_descriptor=True`` can be provided to skip the slower scan for an
44
+ unsigned data descriptor (deprecated in the latest ZIP specification and is
45
+ only used by legacy tools) when checking for bytes resembling a valid local
46
+ file entry. This improves performance, but may cause some stale local file
47
+ entries to be preserved, as any entry using an unsigned descriptor cannot
48
+ be detected.
49
+
50
+ *chunk_size* may be specified to control the buffer size when moving
51
+ entry data (default is 1 MiB).
52
+
53
+ The archive must be opened with mode ``'a'``.
54
+
55
+ Calling `repack` on a closed ZipFile will raise a `ValueError`.
56
+
57
+ * `ZipFile.copy(zinfo_or_arcname, new_arcname[, chunk_size])`
58
+
59
+ Copies a member *zinfo_or_arcname* to *new_arcname* in the archive.
60
+ *zinfo_or_arcname* may be the full path of the member or a `ZipInfo`
61
+ instance.
62
+
63
+ *chunk_size* may be specified to control the buffer size when copying
64
+ entry data (default is 1 MiB).
65
+
66
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``, and the
67
+ underlying stream must be seekable.
68
+
69
+ Returns the original version of the copied `ZipInfo` instance.
70
+
71
+ Calling `copy` on a closed ZipFile will raise a `ValueError`.
72
+
73
+
74
+ ## Examples
75
+
76
+ ### Remove files and reclaim space
77
+
78
+ ```python
79
+ import os
80
+ import zipremove as zipfile
81
+
82
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
83
+ zh.writestr('file1', 'content1')
84
+ zh.writestr('file2', 'content2')
85
+ zh.writestr('file3', 'content3')
86
+ zh.writestr('file4', 'content4')
87
+
88
+ print(os.path.getsize('archive.zip')) # 398
89
+
90
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
91
+ zh.remove('file1')
92
+ zh.remove('file2')
93
+ zh.remove('file3')
94
+ zh.repack()
95
+
96
+ print(os.path.getsize('archive.zip')) # 116
97
+ ```
98
+
99
+ ### Remove files under a directory and reclaim space
100
+
101
+ ```python
102
+ import os
103
+ import zipremove as zipfile
104
+
105
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
106
+ zh.writestr('file0', 'content0')
107
+ zh.writestr('folder/file1', 'content1')
108
+ zh.writestr('folder/file2', 'content2')
109
+ zh.writestr('folder/file3', 'content3')
110
+
111
+ print(os.path.getsize('archive.zip')) # 440
112
+
113
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
114
+ zinfos = [zh.remove(n) for n in zh.namelist() if n.startswith('folder/')]
115
+ zh.repack(zinfos)
116
+
117
+ print(os.path.getsize('archive.zip')) # 116
118
+ ```
119
+
120
+ ### Rename files under a directory and reclaim space
121
+
122
+ ```python
123
+ import os
124
+ import zipremove as zipfile
125
+
126
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
127
+ zh.writestr('file0', 'content0')
128
+ zh.writestr('folder1/file1', 'content1')
129
+ zh.writestr('folder1/file2', 'content2')
130
+ zh.writestr('folder1/file3', 'content3')
131
+
132
+ print(os.path.getsize('archive.zip')) # 446
133
+
134
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
135
+ for n in zh.namelist():
136
+ if n.startswith('folder1/'):
137
+ n2 = 'folder2/' + n[len('folder1/'):]
138
+ zh.copy(n, n2)
139
+ zh.remove(n)
140
+ zh.repack()
141
+
142
+ print(os.path.getsize('archive.zip')) # 446
143
+ ```
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,66 @@
1
+ [metadata]
2
+ name = zipremove
3
+ version = 0.1.0
4
+ author = Danny Lin
5
+ author_email = danny0838@gmail.com
6
+ url = https://github.com/danny0838/zipremove
7
+ description = Extend `zipfile` with `remove`-related functionalities
8
+ long_description = file: README.md
9
+ long_description_content_type = text/markdown
10
+ license = MIT
11
+ classifiers =
12
+ Development Status :: 4 - Beta
13
+ Intended Audience :: Developers
14
+ Topic :: System :: Archiving :: Compression
15
+ Programming Language :: Python :: 3
16
+ Programming Language :: Python :: 3.9
17
+ Programming Language :: Python :: 3.10
18
+ Programming Language :: Python :: 3.11
19
+ Programming Language :: Python :: 3.12
20
+ Programming Language :: Python :: 3.13
21
+ Programming Language :: Python :: 3.14
22
+ Operating System :: OS Independent
23
+
24
+ [options]
25
+ python_requires = ~=3.9
26
+
27
+ [options.extras_require]
28
+ dev =
29
+ tox >= 4.0
30
+ build
31
+ twine >= 4.0
32
+
33
+ flake8 >= 5.0
34
+ flake8-comprehensions >= 3.12
35
+ flake8-bugbear >= 22.0
36
+ flake8-isort >= 6.0
37
+ isort >= 5.5
38
+
39
+ [flake8]
40
+ exclude =
41
+ .git
42
+ .venv
43
+ .tox
44
+ __pycache__
45
+ build
46
+ setup.py
47
+ max-line-length = 130
48
+ ignore =
49
+ E122
50
+ E226
51
+ E302
52
+ E305
53
+ F403
54
+ F405
55
+ W504
56
+
57
+ [isort]
58
+ multi_line_output = 3
59
+ include_trailing_comma = true
60
+ extend_skip =
61
+ setup.py
62
+
63
+ [egg_info]
64
+ tag_build =
65
+ tag_date = 0
66
+
@@ -0,0 +1,2 @@
1
+ from setuptools import setup
2
+ setup()