zipremove 0.1.0__tar.gz → 0.2.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,211 @@
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.2.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
+ Call `ZipFile.repack` afterwards to reclaim space.
48
+
49
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.
50
+
51
+ Returns the removed `ZipInfo` instance.
52
+
53
+ Calling `remove` on a closed ZipFile will raise a `ValueError`.
54
+
55
+ * `ZipFile.repack(removed=None, *, strict_descriptor=False[, chunk_size])`
56
+
57
+ Rewrites the archive to remove stale local file entries, shrinking the ZIP
58
+ file size.
59
+
60
+ If *removed* is provided, it must be a sequence of `ZipInfo` objects
61
+ representing removed entries; only their corresponding local file entries
62
+ will be removed.
63
+
64
+ If *removed* is not provided, local file entries no longer referenced in the
65
+ central directory will be removed. The algorithm assumes that local file
66
+ entries are stored consecutively:
67
+
68
+ 1. Data before the first referenced entry is removed only when it appears to
69
+ be a sequence of consecutive entries with no extra following bytes; extra
70
+ preceeding bytes are preserved.
71
+ 2. Data between referenced entries is removed only when it appears to
72
+ be a sequence of consecutive entries with no extra preceding bytes; extra
73
+ following bytes are preserved.
74
+
75
+ ``strict_descriptor=True`` can be provided to skip the slower scan for an
76
+ unsigned data descriptor (deprecated in the latest ZIP specification and is
77
+ only used by legacy tools) when checking for bytes resembling a valid local
78
+ file entry. This improves performance, but may cause some stale local file
79
+ entries to be preserved, as any entry using an unsigned descriptor cannot
80
+ be detected.
81
+
82
+ *chunk_size* may be specified to control the buffer size when moving
83
+ entry data (default is 1 MiB).
84
+
85
+ The archive must be opened with mode ``'a'``.
86
+
87
+ Calling `repack` on a closed ZipFile will raise a `ValueError`.
88
+
89
+ * `ZipFile.copy(zinfo_or_arcname, new_arcname[, chunk_size])`
90
+
91
+ Copies a member *zinfo_or_arcname* to *new_arcname* in the archive.
92
+ *zinfo_or_arcname* may be the full path of the member or a `ZipInfo`
93
+ instance.
94
+
95
+ *chunk_size* may be specified to control the buffer size when copying
96
+ entry data (default is 1 MiB).
97
+
98
+ The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``, and the
99
+ underlying stream must be seekable.
100
+
101
+ Returns the original version of the copied `ZipInfo` instance.
102
+
103
+ Calling `copy` on a closed ZipFile will raise a `ValueError`.
104
+
105
+
106
+ ## Examples
107
+
108
+ ### Remove entries and reclaim space
109
+
110
+ Call `repack` after `remove`s to reclaim the space of the removed entries:
111
+
112
+ ```python
113
+ import os
114
+ import zipremove as zipfile
115
+
116
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
117
+ zh.writestr('file1', 'content1')
118
+ zh.writestr('file2', 'content2')
119
+ zh.writestr('file3', 'content3')
120
+ zh.writestr('file4', 'content4')
121
+
122
+ print(os.path.getsize('archive.zip')) # 398
123
+
124
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
125
+ zh.remove('file1')
126
+ zh.remove('file2')
127
+ zh.remove('file3')
128
+ zh.repack()
129
+
130
+ print(os.path.getsize('archive.zip')) # 116 (would be 245 without `repack`)
131
+ ```
132
+
133
+ Alternatively, pass the ZipInfo objects of the removed entries, for better
134
+ performance and error-proofing:
135
+
136
+ ```python
137
+ import os
138
+ import zipremove as zipfile
139
+
140
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
141
+ zh.writestr('file1', 'content1')
142
+ zh.writestr('file2', 'content2')
143
+ zh.writestr('file3', 'content3')
144
+ zh.writestr('file4', 'content4')
145
+
146
+ print(os.path.getsize('archive.zip')) # 398
147
+
148
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
149
+ zinfos = []
150
+ zinfos.append(zh.remove('file1'))
151
+ zinfos.append(zh.remove('file2'))
152
+ zinfos.append(zh.remove('file3'))
153
+ zh.repack(zinfos)
154
+
155
+ print(os.path.getsize('archive.zip')) # 116 (would be 245 without `repack`)
156
+ ```
157
+
158
+ ### Move entries under a folder and reclaim space
159
+
160
+ Moving entries in a ZIP file must be done as a combination of `copy`, `remove`,
161
+ and optionally `repack`, because every local file entry contains the filename
162
+ and requires rewriting.
163
+
164
+ ```python
165
+ import os
166
+ import zipremove as zipfile
167
+
168
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
169
+ zh.writestr('file0', 'content0')
170
+ zh.writestr('folder1/file1', 'content1')
171
+ zh.writestr('folder1/file2', 'content2')
172
+ zh.writestr('folder1/file3', 'content3')
173
+
174
+ print(os.path.getsize('archive.zip')) # 446
175
+
176
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
177
+ for n in zh.namelist():
178
+ if n.startswith('folder1/'):
179
+ n2 = 'folder2/' + n[len('folder1/'):]
180
+ zh.copy(n, n2)
181
+ zh.remove(n)
182
+ zh.repack()
183
+
184
+ print(os.path.getsize('archive.zip')) # 446 (would be 599 without `repack`)
185
+ ```
186
+
187
+ Similarly, pass the ZipInfo objects of the copied/removed entries for better
188
+ performance and error-proofing:
189
+
190
+ ```python
191
+ import os
192
+ import zipremove as zipfile
193
+
194
+ with zipfile.ZipFile('archive.zip', 'w') as zh:
195
+ zh.writestr('file0', 'content0')
196
+ zh.writestr('folder1/file1', 'content1')
197
+ zh.writestr('folder1/file2', 'content2')
198
+ zh.writestr('folder1/file3', 'content3')
199
+
200
+ print(os.path.getsize('archive.zip')) # 446
201
+
202
+ with zipfile.ZipFile('archive.zip', 'a') as zh:
203
+ zinfos = []
204
+ for n in zh.namelist():
205
+ if n.startswith('folder1/'):
206
+ n2 = 'folder2/' + n[len('folder1/'):]
207
+ zinfos.append(zh.remove(zh.copy(n, n2)))
208
+ zh.repack(zinfos)
209
+
210
+ print(os.path.getsize('archive.zip')) # 446 (would be 599 without `repack`)
211
+ ```