comparison env/lib/python3.9/site-packages/zipstream_new-1.1.8.dist-info/METADATA @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 Metadata-Version: 2.1
2 Name: zipstream-new
3 Version: 1.1.8
4 Summary: Zipfile generator that takes input files as well as streams
5 Home-page: https://github.com/arjan-s/python-zipstream
6 Author: arjan5
7 Author-email: arjan@anymore.nl
8 License: UNKNOWN
9 Keywords: zip streaming
10 Platform: UNKNOWN
11 Classifier: Programming Language :: Python
12 Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
13 Classifier: Operating System :: OS Independent
14 Classifier: Topic :: System :: Archiving :: Compression
15 Description-Content-Type: text/markdown
16
17
18 # python-zipstream
19
20 zipstream.py is a zip archive generator based on python 3.3's zipfile.py. It was created to
21 generate a zip file generator for streaming (ie web apps). This is beneficial for when you
22 want to provide a downloadable archive of a large collection of regular files, which would be infeasible to
23 generate the archive prior to downloading or of a very large file that you do not want to store entirely on disk or on memory.
24
25 The archive is generated as an iterator of strings, which, when joined, form
26 the zip archive. For example, the following code snippet would write a zip
27 archive containing files from 'path' to a normal file:
28
29 ```python
30 import zipstream
31
32 z = zipstream.ZipFile()
33 z.write('path/to/files')
34
35 with open('zipfile.zip', 'wb') as f:
36 for data in z:
37 f.write(data)
38 ```
39
40 zipstream also allows to take as input a byte string iterable and to generate
41 the archive as an iterator.
42 This avoids storing large files on disk or in memory.
43 To do so you could use something like this snippet:
44
45 ```python
46 def iterable():
47 for _ in xrange(10):
48 yield b'this is a byte string\x01\n'
49
50 z = zipstream.ZipFile()
51 z.write_iter('my_archive_iter', iterable())
52
53 with open('zipfile.zip', 'wb') as f:
54 for data in z:
55 f.write(data)
56 ```
57
58 Of course both approach can be combined:
59
60 ```python
61 def iterable():
62 for _ in xrange(10):
63 yield b'this is a byte string\x01\n'
64
65 z = zipstream.ZipFile()
66 z.write('path/to/files', 'my_archive_files')
67 z.write_iter('my_archive_iter', iterable())
68
69 with open('zipfile.zip', 'wb') as f:
70 for data in z:
71 f.write(data)
72 ```
73
74 Since recent versions of web.py support returning iterators of strings to be
75 sent to the browser, to download a dynamically generated archive, you could
76 use something like this snippet:
77
78 ```python
79 def GET(self):
80 path = '/path/to/dir/of/files'
81 zip_filename = 'files.zip'
82 web.header('Content-type' , 'application/zip')
83 web.header('Content-Disposition', 'attachment; filename="%s"' % (
84 zip_filename,))
85 return zipstream.ZipFile(path)
86 ```
87
88 If the zlib module is available, zipstream.ZipFile can generate compressed zip
89 archives.
90
91 ## Installation
92
93 ```
94 pip install zipstream-new
95 ```
96
97 ## Requirements
98
99 * Python 2.6+, 3.2+, pypy
100
101 ## Examples
102
103 ### flask
104
105 ```python
106 from flask import Response
107
108 @app.route('/package.zip', methods=['GET'], endpoint='zipball')
109 def zipball():
110 def generator():
111 z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)
112
113 z.write('/path/to/file')
114
115 for chunk in z:
116 yield chunk
117
118 response = Response(generator(), mimetype='application/zip')
119 response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')
120 return response
121
122 # or
123
124 @app.route('/package.zip', methods=['GET'], endpoint='zipball')
125 def zipball():
126 z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)
127 z.write('/path/to/file')
128
129 response = Response(z, mimetype='application/zip')
130 response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')
131 return response
132
133 # Partial flushing of the zip before closing
134
135 @app.route('/package.zip', methods=['GET'], endpoint='zipball')
136 def zipball():
137 def generate_zip_with_manifest():
138 z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)
139
140 manifest = []
141 for filename in os.listdir('/path/to/files'):
142 z.write(os.path.join('/path/to/files', filename), arcname=filename)
143 yield from z.flush()
144 manifest.append(filename)
145
146 z.write_str('manifest.json', json.dumps(manifest).encode())
147
148 yield from z
149
150 response = Response(z, mimetype='application/zip')
151 response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')
152 return response
153 ```
154
155 ### django 1.5+
156
157 ```python
158 from django.http import StreamingHttpResponse
159
160 def zipball(request):
161 z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)
162 z.write('/path/to/file')
163
164 response = StreamingHttpResponse(z, content_type='application/zip')
165 response['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')
166 return response
167 ```
168
169 ### webpy
170
171 ```python
172 def GET(self):
173 path = '/path/to/dir/of/files'
174 zip_filename = 'files.zip'
175 web.header('Content-type' , 'application/zip')
176 web.header('Content-Disposition', 'attachment; filename="%s"' % (
177 zip_filename,))
178 return zipstream.ZipFile(path)
179 ```
180
181 ## Running tests
182
183 With python version > 2.6, just run the following command: `python -m unittest discover`
184
185 Alternatively, you can use `nose`.
186
187 If you want to run the tests on all supported Python versions, run `tox`.
188
189