{ "info": { "author": "arjan5", "author_email": "arjan@anymore.nl", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: System :: Archiving :: Compression" ], "description": "\n# python-zipstream\n\nzipstream.py is a zip archive generator based on python 3.3's zipfile.py. It was created to\ngenerate a zip file generator for streaming (ie web apps). This is beneficial for when you\nwant to provide a downloadable archive of a large collection of regular files, which would be infeasible to\ngenerate the archive prior to downloading or of a very large file that you do not want to store entirely on disk or on memory.\n\nThe archive is generated as an iterator of strings, which, when joined, form\nthe zip archive. For example, the following code snippet would write a zip\narchive containing files from 'path' to a normal file:\n\n```python\nimport zipstream\n\nz = zipstream.ZipFile()\nz.write('path/to/files')\n\nwith open('zipfile.zip', 'wb') as f:\n for data in z:\n f.write(data)\n```\n\nzipstream also allows to take as input a byte string iterable and to generate\nthe archive as an iterator.\nThis avoids storing large files on disk or in memory.\nTo do so you could use something like this snippet:\n\n```python\ndef iterable():\n for _ in xrange(10):\n yield b'this is a byte string\\x01\\n'\n\nz = zipstream.ZipFile()\nz.write_iter('my_archive_iter', iterable())\n\nwith open('zipfile.zip', 'wb') as f:\n for data in z:\n f.write(data)\n```\n\nOf course both approach can be combined:\n\n```python\ndef iterable():\n for _ in xrange(10):\n yield b'this is a byte string\\x01\\n'\n\nz = zipstream.ZipFile()\nz.write('path/to/files', 'my_archive_files')\nz.write_iter('my_archive_iter', iterable())\n\nwith open('zipfile.zip', 'wb') as f:\n for data in z:\n f.write(data)\n```\n\nSince recent versions of web.py support returning iterators of strings to be\nsent to the browser, to download a dynamically generated archive, you could\nuse something like this snippet:\n\n```python\ndef GET(self):\n path = '/path/to/dir/of/files'\n zip_filename = 'files.zip'\n web.header('Content-type' , 'application/zip')\n web.header('Content-Disposition', 'attachment; filename=\"%s\"' % (\n zip_filename,))\n return zipstream.ZipFile(path)\n```\n\nIf the zlib module is available, zipstream.ZipFile can generate compressed zip\narchives.\n\n## Installation\n\n```\npip install zipstream-new\n```\n\n## Requirements\n\n * Python 2.6+, 3.2+, pypy\n\n## Examples\n\n### flask\n\n```python\nfrom flask import Response\n\n@app.route('/package.zip', methods=['GET'], endpoint='zipball')\ndef zipball():\n def generator():\n z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)\n\n z.write('/path/to/file')\n\n for chunk in z:\n yield chunk\n\n response = Response(generator(), mimetype='application/zip')\n response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')\n return response\n\n# or\n\n@app.route('/package.zip', methods=['GET'], endpoint='zipball')\ndef zipball():\n z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)\n z.write('/path/to/file')\n\n response = Response(z, mimetype='application/zip')\n response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')\n return response\n\n# Partial flushing of the zip before closing\n\n@app.route('/package.zip', methods=['GET'], endpoint='zipball')\ndef zipball():\n def generate_zip_with_manifest():\n z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)\n\n manifest = []\n for filename in os.listdir('/path/to/files'):\n z.write(os.path.join('/path/to/files', filename), arcname=filename)\n yield from z.flush()\n manifest.append(filename)\n\n z.write_str('manifest.json', json.dumps(manifest).encode())\n\n yield from z\n\n response = Response(z, mimetype='application/zip')\n response.headers['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')\n return response\n```\n\n### django 1.5+\n\n```python\nfrom django.http import StreamingHttpResponse\n\ndef zipball(request):\n z = zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED)\n z.write('/path/to/file')\n\n response = StreamingHttpResponse(z, content_type='application/zip')\n response['Content-Disposition'] = 'attachment; filename={}'.format('files.zip')\n return response\n```\n\n### webpy\n\n```python\ndef GET(self):\n path = '/path/to/dir/of/files'\n zip_filename = 'files.zip'\n web.header('Content-type' , 'application/zip')\n web.header('Content-Disposition', 'attachment; filename=\"%s\"' % (\n zip_filename,))\n return zipstream.ZipFile(path)\n```\n\n## Running tests\n\nWith python version > 2.6, just run the following command: `python -m unittest discover`\n\nAlternatively, you can use `nose`.\n\nIf you want to run the tests on all supported Python versions, run `tox`.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/arjan-s/python-zipstream", "keywords": "zip streaming", "license": "", "maintainer": "", "maintainer_email": "", "name": "zipstream-new", "package_url": "https://pypi.org/project/zipstream-new/", "platform": "", "project_url": "https://pypi.org/project/zipstream-new/", "project_urls": { "Homepage": "https://github.com/arjan-s/python-zipstream" }, "release_url": "https://pypi.org/project/zipstream-new/1.1.8/", "requires_dist": null, "requires_python": "", "summary": "Zipfile generator that takes input files as well as streams", "version": "1.1.8", "yanked": false, "yanked_reason": null }, "last_serial": 8180621, "releases": { "1.1.5": [ { "comment_text": "", "digests": { "md5": "387117436d9c3724a87dd0481491fd24", "sha256": "a9a4573770e4d665502dcc52e82981623ef36e02e7ae1cf30fea6d3de4f7af2f" }, "downloads": -1, "filename": "zipstream_new-1.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "387117436d9c3724a87dd0481491fd24", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 19917, "upload_time": "2019-04-10T07:38:51", "upload_time_iso_8601": "2019-04-10T07:38:51.540053Z", "url": "https://files.pythonhosted.org/packages/c0/26/2c005b3ff0096fd48e8aea1709ca1fc389e527fcf23f41c9f4b85aeec2d1/zipstream_new-1.1.5-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "3d31c490cccb1befbb6a37467682fc23", "sha256": "4b99dcf64a297a2dc01ecc480bdabd098f9dc6319a3302461202c7a94eea2664" }, "downloads": -1, "filename": "zipstream-new-1.1.5.tar.gz", "has_sig": false, "md5_digest": "3d31c490cccb1befbb6a37467682fc23", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7757, "upload_time": "2019-04-10T07:38:54", "upload_time_iso_8601": "2019-04-10T07:38:54.104161Z", "url": "https://files.pythonhosted.org/packages/2f/cd/8bb4098706f2009e842828076bcc0f4ac07bdf59cb81e21f75bbddda9a86/zipstream-new-1.1.5.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.6": [ { "comment_text": "", "digests": { "md5": "3ebc0f470d5c39f9eec7429d07f70d45", "sha256": "4169ee58167d88eafedd44fa89f0342f23e0806e15d4b7a61c93ed9df99570b1" }, "downloads": -1, "filename": "zipstream_new-1.1.6-py3-none-any.whl", "has_sig": false, "md5_digest": "3ebc0f470d5c39f9eec7429d07f70d45", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20087, "upload_time": "2019-06-06T08:49:45", "upload_time_iso_8601": "2019-06-06T08:49:45.796782Z", "url": "https://files.pythonhosted.org/packages/3e/22/f4e30bf9af44ce0d9691e3d3176982c57bb3ec91d14c9d81e628fa9276f1/zipstream_new-1.1.6-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "0e0f277f4f61027c8fdab97880f181b1", "sha256": "fcc82345ab46e924d5905ad5f8f14dd69ebc29feb06dc0669f9a256deaed7235" }, "downloads": -1, "filename": "zipstream-new-1.1.6.tar.gz", "has_sig": false, "md5_digest": "0e0f277f4f61027c8fdab97880f181b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7973, "upload_time": "2019-06-06T08:49:47", "upload_time_iso_8601": "2019-06-06T08:49:47.414656Z", "url": "https://files.pythonhosted.org/packages/5b/66/5d9df14b3bef36564943cdf72eac73816f6f709afe042fe1b10e52f81319/zipstream-new-1.1.6.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.7": [ { "comment_text": "", "digests": { "md5": "c32e87e65b6c4e1e4462005a51f292a5", "sha256": "779d47c2c47934db610f8ce25ad5bd3bee33d805fe3ea1675f50ba0b01fb6497" }, "downloads": -1, "filename": "zipstream_new-1.1.7-py3-none-any.whl", "has_sig": false, "md5_digest": "c32e87e65b6c4e1e4462005a51f292a5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20118, "upload_time": "2019-10-22T10:54:21", "upload_time_iso_8601": "2019-10-22T10:54:21.218787Z", "url": "https://files.pythonhosted.org/packages/df/5b/ec12571029f23e083607cc2f4a47aa735d89248d00be7122167bd00d651a/zipstream_new-1.1.7-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "6a4759fd1358e41df0c7fef53284d743", "sha256": "c5708462c5a12e227b3407e46489b5ffb516c38330983f1638d6cea83e653fb1" }, "downloads": -1, "filename": "zipstream-new-1.1.7.tar.gz", "has_sig": false, "md5_digest": "6a4759fd1358e41df0c7fef53284d743", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8022, "upload_time": "2019-10-22T10:54:23", "upload_time_iso_8601": "2019-10-22T10:54:23.154884Z", "url": "https://files.pythonhosted.org/packages/02/85/48f2cc265490cbd435a03877ebb05ea975cac93fc42c661f8c313c4da88d/zipstream-new-1.1.7.tar.gz", "yanked": false, "yanked_reason": null } ], "1.1.8": [ { "comment_text": "", "digests": { "md5": "5a50ff1a51e34a2161764455cb71f501", "sha256": "0662eb3ebe764fa168a5883cd8819ef83b94bd9e39955537188459d2264a7f60" }, "downloads": -1, "filename": "zipstream_new-1.1.8-py3-none-any.whl", "has_sig": false, "md5_digest": "5a50ff1a51e34a2161764455cb71f501", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20168, "upload_time": "2020-09-14T09:26:42", "upload_time_iso_8601": "2020-09-14T09:26:42.733531Z", "url": "https://files.pythonhosted.org/packages/81/f3/d7b4c8c9b6657ff0db27b739894ed0665fa8f3c78a7452bf74d6447f6865/zipstream_new-1.1.8-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "acd41cc94496e08bd8e86a83b214d9e0", "sha256": "b031fe181b94e51678389d26b174bc76382605a078d7d5d8f5beae083f111c76" }, "downloads": -1, "filename": "zipstream-new-1.1.8.tar.gz", "has_sig": false, "md5_digest": "acd41cc94496e08bd8e86a83b214d9e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9377, "upload_time": "2020-09-14T09:26:44", "upload_time_iso_8601": "2020-09-14T09:26:44.566776Z", "url": "https://files.pythonhosted.org/packages/e5/f3/1b5228576f215b200c7e922a280a92e4494df33baae6e0280a6f45371f13/zipstream-new-1.1.8.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5a50ff1a51e34a2161764455cb71f501", "sha256": "0662eb3ebe764fa168a5883cd8819ef83b94bd9e39955537188459d2264a7f60" }, "downloads": -1, "filename": "zipstream_new-1.1.8-py3-none-any.whl", "has_sig": false, "md5_digest": "5a50ff1a51e34a2161764455cb71f501", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20168, "upload_time": "2020-09-14T09:26:42", "upload_time_iso_8601": "2020-09-14T09:26:42.733531Z", "url": "https://files.pythonhosted.org/packages/81/f3/d7b4c8c9b6657ff0db27b739894ed0665fa8f3c78a7452bf74d6447f6865/zipstream_new-1.1.8-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "acd41cc94496e08bd8e86a83b214d9e0", "sha256": "b031fe181b94e51678389d26b174bc76382605a078d7d5d8f5beae083f111c76" }, "downloads": -1, "filename": "zipstream-new-1.1.8.tar.gz", "has_sig": false, "md5_digest": "acd41cc94496e08bd8e86a83b214d9e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9377, "upload_time": "2020-09-14T09:26:44", "upload_time_iso_8601": "2020-09-14T09:26:44.566776Z", "url": "https://files.pythonhosted.org/packages/e5/f3/1b5228576f215b200c7e922a280a92e4494df33baae6e0280a6f45371f13/zipstream-new-1.1.8.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }