Giter Club home page Giter Club logo

zipstream's Introduction

minio-zipstream

This is a fork from kbbdy/zipstream for implementing multiple object download from S3 backend.

Simple python library for streaming ZIP files which are created dynamically, without using any temporary files.

Files stored in ZIP file are not compressed. Its intended to serve easily structured content in convenient way in web applications

  • No temporary files, data is streamed directly from files
  • Small memory usage, straming is realised using yield statement
  • Archive structure is created on the fly
  • Zip32 compatible files
  • Zip64 support is planned in future
  • Independent from python's standard lib implementation

Examples:

Example of creating zip file

from zipstream import ZipStream
from minio import Minio
from minio.error import ResponseError

s3Client = Minio('s3.amazonaws.com',
                 access_key='ACCESS_KEY',
                 secret_key='SECRET_KEY')

zs = ZipStream()

# List all object paths in bucket that begin with my-prefixname.
objects = s3client.list_objects('mybucket', prefix='my-prefixname',
                                   recursive=True)
for obj in objects:
    zs.add_file(obj.object_name, obj.size, obj.last_modified)

# write result file
with file("attachment.zip","wb") as fout:
    for f in zs.stream():
        fout.write(f)

Example of using zipstream as Django view

from django.http import StreamingHttpResponse
from os.path import basename as get_object_base_name

def stream_as_zip(request, object_names):
    streamed_data_filename = "my_streamed_zip_file.zip"
    # large chunk size will improve speed, but increase memory usage
    stream = ZipStream(chunksize=32768)
    
    for object_name in object_names:
        # filename of first file in ZIP archive will be different than original
        stream.add_file(get_object_base_name(object_name))

    # streamed response
    response = StreamingHttpResponse(
        stream.stream(),
        content_type="application/zip")
    response['Content-Disposition'] =
        'attachment; filename="%s"' % streamed_data_filename
    return response

zipstream's People

Contributors

kbbdy avatar muminoff avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.