zipremove 0.1.0__tar.gz → 0.3.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.
@@ -1,21 +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.
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.
@@ -1,176 +1,218 @@
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
- ```
1
+ Metadata-Version: 2.4
2
+ Name: zipremove
3
+ Version: 0.3.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 :: Only
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: ~=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE.txt
24
+ Provides-Extra: dev
25
+ Requires-Dist: tox>=4.0; extra == "dev"
26
+ Requires-Dist: build; extra == "dev"
27
+ Requires-Dist: twine>=4.0; extra == "dev"
28
+ Requires-Dist: flake8>=5.0; extra == "dev"
29
+ Requires-Dist: flake8-comprehensions>=3.12; extra == "dev"
30
+ Requires-Dist: flake8-bugbear>=22.0; extra == "dev"
31
+ Requires-Dist: flake8-isort>=6.0; extra == "dev"
32
+ Requires-Dist: isort>=5.5; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ ![PyPI version](https://img.shields.io/pypi/v/zipremove.svg)
36
+ ![Python Versions](https://img.shields.io/pypi/pyversions/zipremove)
37
+ ![Status](https://img.shields.io/pypi/status/zipremove)
38
+ ![License](https://img.shields.io/github/license/danny0838/zipremove)
39
+ [![Downloads](https://static.pepy.tech/personalized-badge/zipremove?period=month&left_text=Downloads)](https://pepy.tech/project/zipremove)
40
+
41
+ This package extends `zipfile` with `remove`-related functionalities.
42
+
43
+ ## API
44
+
45
+ * `ZipFile.remove(zinfo_or_arcname)`
46
+
47
+ Removes a member from the archive. *zinfo_or_arcname* may be the full path
48
+ of the member or a `ZipInfo` instance.
49
+
50
+ If multiple members share the same full path, only one is removed when
51
+ a path is provided.
52
+
53
+ This does not physically remove the local file entry from the archive.
54
+ Call `ZipFile.repack` afterwards to reclaim space.
55
+
56
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.
57
+
58
+ Returns the removed `ZipInfo` instance.
59
+
60
+ Calling `remove` on a closed ZipFile will raise a `ValueError`.
61
+
62
+ * `ZipFile.repack(removed=None, *, strict_descriptor=False[, chunk_size])`
63
+
64
+ Rewrites the archive to remove stale local file entries, shrinking the ZIP
65
+ file size.
66
+
67
+ If *removed* is provided, it must be a sequence of `ZipInfo` objects
68
+ representing removed entries; only their corresponding local file entries
69
+ will be removed.
70
+
71
+ If *removed* is not provided, local file entries no longer referenced in the
72
+ central directory will be removed. The algorithm assumes that local file
73
+ entries are stored consecutively:
74
+
75
+ 1. Data before the first referenced entry is removed only when it appears to
76
+ be a sequence of consecutive entries with no extra following bytes; extra
77
+ preceeding bytes are preserved.
78
+ 2. Data between referenced entries is removed only when it appears to
79
+ be a sequence of consecutive entries with no extra preceding bytes; extra
80
+ following bytes are preserved.
81
+
82
+ ``strict_descriptor=True`` can be provided to skip the slower scan for an
83
+ unsigned data descriptor (deprecated in the latest ZIP specification and is
84
+ only used by legacy tools) when checking for bytes resembling a valid local
85
+ file entry. This improves performance, but may cause some stale local file
86
+ entries to be preserved, as any entry using an unsigned descriptor cannot
87
+ be detected.
88
+
89
+ *chunk_size* may be specified to control the buffer size when moving
90
+ entry data (default is 1 MiB).
91
+
92
+ The archive must be opened with mode ``'a'``.
93
+
94
+ Calling `repack` on a closed ZipFile will raise a `ValueError`.
95
+
96
+ * `ZipFile.copy(zinfo_or_arcname, new_arcname[, chunk_size])`
97
+
98
+ Copies a member *zinfo_or_arcname* to *new_arcname* in the archive.
99
+ *zinfo_or_arcname* may be the full path of the member or a `ZipInfo`
100
+ instance.
101
+
102
+ *chunk_size* may be specified to control the buffer size when copying
103
+ entry data (default is 1 MiB).
104
+
105
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``, and the
106
+ underlying stream must be seekable.
107
+
108
+ Returns the original version of the copied `ZipInfo` instance.
109
+
110
+ Calling `copy` on a closed ZipFile will raise a `ValueError`.
111
+
112
+
113
+ ## Examples
114
+
115
+ ### Remove entries and reclaim space
116
+
117
+ Call `repack` after `remove`s to reclaim the space of the removed entries:
118
+
119
+ ```python
120
+ import os
121
+ import zipremove as zipfile
122
+
123
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
124
+ zh.writestr('file1', 'content1')
125
+ zh.writestr('file2', 'content2')
126
+ zh.writestr('file3', 'content3')
127
+ zh.writestr('file4', 'content4')
128
+
129
+ print(os.path.getsize('archive.zip')) # 398
130
+
131
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
132
+ zh.remove('file1')
133
+ zh.remove('file2')
134
+ zh.remove('file3')
135
+ zh.repack()
136
+
137
+ print(os.path.getsize('archive.zip')) # 116 (would be 245 without `repack`)
138
+ ```
139
+
140
+ Alternatively, pass the ZipInfo objects of the removed entries, for better
141
+ performance and error-proofing:
142
+
143
+ ```python
144
+ import os
145
+ import zipremove as zipfile
146
+
147
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
148
+ zh.writestr('file1', 'content1')
149
+ zh.writestr('file2', 'content2')
150
+ zh.writestr('file3', 'content3')
151
+ zh.writestr('file4', 'content4')
152
+
153
+ print(os.path.getsize('archive.zip')) # 398
154
+
155
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
156
+ zinfos = []
157
+ zinfos.append(zh.remove('file1'))
158
+ zinfos.append(zh.remove('file2'))
159
+ zinfos.append(zh.remove('file3'))
160
+ zh.repack(zinfos)
161
+
162
+ print(os.path.getsize('archive.zip')) # 116 (would be 245 without `repack`)
163
+ ```
164
+
165
+ ### Move entries under a folder and reclaim space
166
+
167
+ Moving entries in a ZIP file must be done as a combination of `copy`, `remove`,
168
+ and optionally `repack`, because every local file entry contains the filename
169
+ and requires rewriting.
170
+
171
+ ```python
172
+ import os
173
+ import zipremove as zipfile
174
+
175
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
176
+ zh.writestr('file0', 'content0')
177
+ zh.writestr('folder1/file1', 'content1')
178
+ zh.writestr('folder1/file2', 'content2')
179
+ zh.writestr('folder1/file3', 'content3')
180
+
181
+ print(os.path.getsize('archive.zip')) # 446
182
+
183
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
184
+ for n in zh.namelist():
185
+ if n.startswith('folder1/'):
186
+ n2 = 'folder2/' + n[len('folder1/'):]
187
+ zh.copy(n, n2)
188
+ zh.remove(n)
189
+ zh.repack()
190
+
191
+ print(os.path.getsize('archive.zip')) # 446 (would be 599 without `repack`)
192
+ ```
193
+
194
+ Similarly, pass the ZipInfo objects of the copied/removed entries for better
195
+ performance and error-proofing:
196
+
197
+ ```python
198
+ import os
199
+ import zipremove as zipfile
200
+
201
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
202
+ zh.writestr('file0', 'content0')
203
+ zh.writestr('folder1/file1', 'content1')
204
+ zh.writestr('folder1/file2', 'content2')
205
+ zh.writestr('folder1/file3', 'content3')
206
+
207
+ print(os.path.getsize('archive.zip')) # 446
208
+
209
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
210
+ zinfos = []
211
+ for n in zh.namelist():
212
+ if n.startswith('folder1/'):
213
+ n2 = 'folder2/' + n[len('folder1/'):]
214
+ zinfos.append(zh.remove(zh.copy(n, n2)))
215
+ zh.repack(zinfos)
216
+
217
+ print(os.path.getsize('archive.zip')) # 446 (would be 599 without `repack`)
218
+ ```