Giter VIP home page Giter VIP logo

gzip-stream's Introduction

gzip-stream

gzip-stream is a super-tiny library that will help you compress by GZIP on-the-fly.

GZIPCompressedStream class instance acting like an any other stream (in fact, GZIPCompressedStream inherits io.RawIOBase), but wraps another stream and compress it on-the-fly.

from gzip_stream import GZIPCompressedStream
from my_upload_lib import MyUploadClient

upload_client = MyUploadClient()
with open('my_very_big_1tb_file.txt') as file_to_upload:
    compressed_stream = GZIPCompressedStream(
        file_to_upload,
        compression_level=7
    )
    upload_client.upload_fileobj(compressed_stream)

GZIPCompressedStream does not read entire stream, but instead read it by chunks, until compressed output size will not satisfy read size.

AsyncGZIPDecompressedStream class can async read from another source with zlib and gzip decompression on-the-fly

# aiobotocore example

import aiobotocore

from gzip_stream import AsyncGZIPDecompressedStream

AWS_ACCESS_KEY_ID = "KEY_ID"
AWS_SECRET_ACCESS_KEY = "ACCESS_KEY"
BUCKET = "AWESOME_BUCKET"

upload_client = MyAsyncUploadClient()
session = aiobotocore.get_session()
async with session.create_client(
    service_name="s3",
    endpoint_url="s3_endpoint",
    aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
    aws_access_key_id=AWS_ACCESS_KEY_ID,
) as client:
    response = await client.get_object(Bucket=BUCKET, Key='my_very_big_1tb_file.txt.gz')
    async for decompressed_chunk in GzipAsyncReaderWrapper(response["Body"])):
        await upload_client.upload_fileobj(decompressed_chunk)

Module works on Python ~= 3.5.

Installation

pip install gzip-stream

License

Public Domain: CC0 1.0 Universal.

gzip-stream's People

Contributors

0x446 avatar leenr avatar lukeplausin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gzip-stream's Issues

Feature request - decompress stream

Thanks for writing this module - it seems quite useful.
Would it be possible to add a streaming decompress feature as well? I think this would be a nice addition

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.