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.
- {zipremove-0.1.0 → zipremove-0.3.0}/LICENSE.txt +21 -21
- {zipremove-0.1.0/src/zipremove.egg-info → zipremove-0.3.0}/PKG-INFO +218 -176
- {zipremove-0.1.0 → zipremove-0.3.0}/README.md +184 -143
- {zipremove-0.1.0 → zipremove-0.3.0}/pyproject.toml +3 -3
- {zipremove-0.1.0 → zipremove-0.3.0}/setup.cfg +67 -66
- {zipremove-0.1.0 → zipremove-0.3.0}/setup.py +2 -2
- {zipremove-0.1.0 → zipremove-0.3.0}/src/zipremove/__init__.py +660 -647
- {zipremove-0.1.0 → zipremove-0.3.0/src/zipremove.egg-info}/PKG-INFO +218 -176
- {zipremove-0.1.0 → zipremove-0.3.0}/tests/test_zipfile.py +2000 -1712
- {zipremove-0.1.0 → zipremove-0.3.0}/tests/test_zipfile64.py +210 -176
- {zipremove-0.1.0 → zipremove-0.3.0}/src/zipremove.egg-info/SOURCES.txt +0 -0
- {zipremove-0.1.0 → zipremove-0.3.0}/src/zipremove.egg-info/dependency_links.txt +0 -0
- {zipremove-0.1.0 → zipremove-0.3.0}/src/zipremove.egg-info/requires.txt +0 -0
- {zipremove-0.1.0 → zipremove-0.3.0}/src/zipremove.egg-info/top_level.txt +0 -0
|
@@ -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.
|
|
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
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.
|
|
19
|
-
Classifier:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Requires-Dist:
|
|
26
|
-
Requires-Dist:
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist: flake8
|
|
29
|
-
Requires-Dist: flake8-
|
|
30
|
-
Requires-Dist: flake8-
|
|
31
|
-
Requires-Dist: isort>=
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
with zipfile.ZipFile('archive.zip', '
|
|
124
|
-
zh.
|
|
125
|
-
zh.
|
|
126
|
-
zh.
|
|
127
|
-
zh.
|
|
128
|
-
|
|
129
|
-
print(os.path.getsize('archive.zip')) #
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
zh.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
zh.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
+

|
|
36
|
+

|
|
37
|
+

|
|
38
|
+

|
|
39
|
+
[](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
|
+
```
|