diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-zipstream-new.spec | 591 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 593 insertions, 0 deletions
@@ -0,0 +1 @@ +/zipstream-new-1.1.8.tar.gz diff --git a/python-zipstream-new.spec b/python-zipstream-new.spec new file mode 100644 index 0000000..8675929 --- /dev/null +++ b/python-zipstream-new.spec @@ -0,0 +1,591 @@ +%global _empty_manifest_terminate_build 0 +Name: python-zipstream-new +Version: 1.1.8 +Release: 1 +Summary: Zipfile generator that takes input files as well as streams +License: GNU General Public License v3 (GPLv3) +URL: https://github.com/arjan-s/python-zipstream +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/e5/f3/1b5228576f215b200c7e922a280a92e4494df33baae6e0280a6f45371f13/zipstream-new-1.1.8.tar.gz +BuildArch: noarch + + +%description + +# python-zipstream + +zipstream.py is a zip archive generator based on python 3.3's zipfile.py. It was created to +generate a zip file generator for streaming (ie web apps). This is beneficial for when you +want to provide a downloadable archive of a large collection of regular files, which would be infeasible to +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. + +The archive is generated as an iterator of strings, which, when joined, form +the zip archive. For example, the following code snippet would write a zip +archive containing files from 'path' to a normal file: + +```python +import zipstream + +z = zipstream.ZipFile() +z.write('path/to/files') + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +zipstream also allows to take as input a byte string iterable and to generate +the archive as an iterator. +This avoids storing large files on disk or in memory. +To do so you could use something like this snippet: + +```python +def iterable(): + for _ in xrange(10): + yield b'this is a byte string\x01\n' + +z = zipstream.ZipFile() +z.write_iter('my_archive_iter', iterable()) + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +Of course both approach can be combined: + +```python +def iterable(): + for _ in xrange(10): + yield b'this is a byte string\x01\n' + +z = zipstream.ZipFile() +z.write('path/to/files', 'my_archive_files') +z.write_iter('my_archive_iter', iterable()) + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +Since recent versions of web.py support returning iterators of strings to be +sent to the browser, to download a dynamically generated archive, you could +use something like this snippet: + +```python +def GET(self): + path = '/path/to/dir/of/files' + zip_filename = 'files.zip' + web.header('Content-type' , 'application/zip') + web.header('Content-Disposition', 'attachment; filename="%s"' % ( + zip_filename,)) + return zipstream.ZipFile(path) +``` + +If the zlib module is available, zipstream.ZipFile can generate compressed zip +archives. + +## Installation + +``` +pip install zipstream-new +``` + +## Requirements + + * Python 2.6+, 3.2+, pypy + +## Examples + +### flask + +```python +from flask import Response + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + def generator(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + + z.write('/path/to/file') + + for chunk in z: + yield chunk + + response = Response(generator(), mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response + +# or + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + z.write('/path/to/file') + + response = Response(z, mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response + +# Partial flushing of the zip before closing + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + def generate_zip_with_manifest(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + + manifest = [] + for filename in os.listdir('/path/to/files'): + z.write(os.path.join('/path/to/files', filename), arcname=filename) + yield from z.flush() + manifest.append(filename) + + z.write_str('manifest.json', json.dumps(manifest).encode()) + + yield from z + + response = Response(z, mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response +``` + +### django 1.5+ + +```python +from django.http import StreamingHttpResponse + +def zipball(request): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + z.write('/path/to/file') + + response = StreamingHttpResponse(z, content_type='application/zip') + response['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response +``` + +### webpy + +```python +def GET(self): + path = '/path/to/dir/of/files' + zip_filename = 'files.zip' + web.header('Content-type' , 'application/zip') + web.header('Content-Disposition', 'attachment; filename="%s"' % ( + zip_filename,)) + return zipstream.ZipFile(path) +``` + +## Running tests + +With python version > 2.6, just run the following command: `python -m unittest discover` + +Alternatively, you can use `nose`. + +If you want to run the tests on all supported Python versions, run `tox`. + + + + +%package -n python3-zipstream-new +Summary: Zipfile generator that takes input files as well as streams +Provides: python-zipstream-new +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-zipstream-new + +# python-zipstream + +zipstream.py is a zip archive generator based on python 3.3's zipfile.py. It was created to +generate a zip file generator for streaming (ie web apps). This is beneficial for when you +want to provide a downloadable archive of a large collection of regular files, which would be infeasible to +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. + +The archive is generated as an iterator of strings, which, when joined, form +the zip archive. For example, the following code snippet would write a zip +archive containing files from 'path' to a normal file: + +```python +import zipstream + +z = zipstream.ZipFile() +z.write('path/to/files') + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +zipstream also allows to take as input a byte string iterable and to generate +the archive as an iterator. +This avoids storing large files on disk or in memory. +To do so you could use something like this snippet: + +```python +def iterable(): + for _ in xrange(10): + yield b'this is a byte string\x01\n' + +z = zipstream.ZipFile() +z.write_iter('my_archive_iter', iterable()) + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +Of course both approach can be combined: + +```python +def iterable(): + for _ in xrange(10): + yield b'this is a byte string\x01\n' + +z = zipstream.ZipFile() +z.write('path/to/files', 'my_archive_files') +z.write_iter('my_archive_iter', iterable()) + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +Since recent versions of web.py support returning iterators of strings to be +sent to the browser, to download a dynamically generated archive, you could +use something like this snippet: + +```python +def GET(self): + path = '/path/to/dir/of/files' + zip_filename = 'files.zip' + web.header('Content-type' , 'application/zip') + web.header('Content-Disposition', 'attachment; filename="%s"' % ( + zip_filename,)) + return zipstream.ZipFile(path) +``` + +If the zlib module is available, zipstream.ZipFile can generate compressed zip +archives. + +## Installation + +``` +pip install zipstream-new +``` + +## Requirements + + * Python 2.6+, 3.2+, pypy + +## Examples + +### flask + +```python +from flask import Response + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + def generator(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + + z.write('/path/to/file') + + for chunk in z: + yield chunk + + response = Response(generator(), mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response + +# or + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + z.write('/path/to/file') + + response = Response(z, mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response + +# Partial flushing of the zip before closing + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + def generate_zip_with_manifest(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + + manifest = [] + for filename in os.listdir('/path/to/files'): + z.write(os.path.join('/path/to/files', filename), arcname=filename) + yield from z.flush() + manifest.append(filename) + + z.write_str('manifest.json', json.dumps(manifest).encode()) + + yield from z + + response = Response(z, mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response +``` + +### django 1.5+ + +```python +from django.http import StreamingHttpResponse + +def zipball(request): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + z.write('/path/to/file') + + response = StreamingHttpResponse(z, content_type='application/zip') + response['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response +``` + +### webpy + +```python +def GET(self): + path = '/path/to/dir/of/files' + zip_filename = 'files.zip' + web.header('Content-type' , 'application/zip') + web.header('Content-Disposition', 'attachment; filename="%s"' % ( + zip_filename,)) + return zipstream.ZipFile(path) +``` + +## Running tests + +With python version > 2.6, just run the following command: `python -m unittest discover` + +Alternatively, you can use `nose`. + +If you want to run the tests on all supported Python versions, run `tox`. + + + + +%package help +Summary: Development documents and examples for zipstream-new +Provides: python3-zipstream-new-doc +%description help + +# python-zipstream + +zipstream.py is a zip archive generator based on python 3.3's zipfile.py. It was created to +generate a zip file generator for streaming (ie web apps). This is beneficial for when you +want to provide a downloadable archive of a large collection of regular files, which would be infeasible to +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. + +The archive is generated as an iterator of strings, which, when joined, form +the zip archive. For example, the following code snippet would write a zip +archive containing files from 'path' to a normal file: + +```python +import zipstream + +z = zipstream.ZipFile() +z.write('path/to/files') + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +zipstream also allows to take as input a byte string iterable and to generate +the archive as an iterator. +This avoids storing large files on disk or in memory. +To do so you could use something like this snippet: + +```python +def iterable(): + for _ in xrange(10): + yield b'this is a byte string\x01\n' + +z = zipstream.ZipFile() +z.write_iter('my_archive_iter', iterable()) + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +Of course both approach can be combined: + +```python +def iterable(): + for _ in xrange(10): + yield b'this is a byte string\x01\n' + +z = zipstream.ZipFile() +z.write('path/to/files', 'my_archive_files') +z.write_iter('my_archive_iter', iterable()) + +with open('zipfile.zip', 'wb') as f: + for data in z: + f.write(data) +``` + +Since recent versions of web.py support returning iterators of strings to be +sent to the browser, to download a dynamically generated archive, you could +use something like this snippet: + +```python +def GET(self): + path = '/path/to/dir/of/files' + zip_filename = 'files.zip' + web.header('Content-type' , 'application/zip') + web.header('Content-Disposition', 'attachment; filename="%s"' % ( + zip_filename,)) + return zipstream.ZipFile(path) +``` + +If the zlib module is available, zipstream.ZipFile can generate compressed zip +archives. + +## Installation + +``` +pip install zipstream-new +``` + +## Requirements + + * Python 2.6+, 3.2+, pypy + +## Examples + +### flask + +```python +from flask import Response + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + def generator(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + + z.write('/path/to/file') + + for chunk in z: + yield chunk + + response = Response(generator(), mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response + +# or + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + z.write('/path/to/file') + + response = Response(z, mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response + +# Partial flushing of the zip before closing + +@app.route('/package.zip', methods=['GET'], endpoint='zipball') +def zipball(): + def generate_zip_with_manifest(): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + + manifest = [] + for filename in os.listdir('/path/to/files'): + z.write(os.path.join('/path/to/files', filename), arcname=filename) + yield from z.flush() + manifest.append(filename) + + z.write_str('manifest.json', json.dumps(manifest).encode()) + + yield from z + + response = Response(z, mimetype='application/zip') + response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response +``` + +### django 1.5+ + +```python +from django.http import StreamingHttpResponse + +def zipball(request): + z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) + z.write('/path/to/file') + + response = StreamingHttpResponse(z, content_type='application/zip') + response['Content-Disposition'] = 'attachment; filename={}'.format('files.zip') + return response +``` + +### webpy + +```python +def GET(self): + path = '/path/to/dir/of/files' + zip_filename = 'files.zip' + web.header('Content-type' , 'application/zip') + web.header('Content-Disposition', 'attachment; filename="%s"' % ( + zip_filename,)) + return zipstream.ZipFile(path) +``` + +## Running tests + +With python version > 2.6, just run the following command: `python -m unittest discover` + +Alternatively, you can use `nose`. + +If you want to run the tests on all supported Python versions, run `tox`. + + + + +%prep +%autosetup -n zipstream-new-1.1.8 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-zipstream-new -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon Apr 10 2023 Python_Bot <Python_Bot@openeuler.org> - 1.1.8-1 +- Package Spec generated @@ -0,0 +1 @@ +acd41cc94496e08bd8e86a83b214d9e0 zipstream-new-1.1.8.tar.gz |