Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-inflate

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-inflate

Uncompress DEFLATE streams in pure Python (albeit compiled with Cython)

  • 0.0.41
  • Source
  • PyPI
  • Socket score

Maintainers
1

stream-inflate PyPI package Test suite Code coverage

Uncompress Deflate and Deflate64 streams in pure Python (albeit compiled with Cython).

Installation

pip install stream-inflate

Usage

To uncompress Deflate, use the stream_inflate function.

from stream_inflate import stream_inflate
import httpx

def compressed_chunks():
    # Iterable that yields the bytes of a DEFLATE-compressed stream
    with httpx.stream('GET', 'https://www.example.com/my.txt') as r:
        yield from r.iter_raw(chunk_size=65536)

for uncompressed_chunk in stream_inflate()[0](compressed_chunks()):
    print(uncompressed_chunk)

To uncompress Deflate64, use the stream_inflate64 function.

for uncompressed_chunk in stream_inflate64()[0](compressed_chunks()):
    print(uncompressed_chunk)

For Deflate streams of unknown length where there may be other data after the compressed part, the following pattern can be used to find how many bytes are not part of the compressed stream.

uncompressed_chunks, is_done, num_bytes_unconsumed = stream_inflate()
it = iter(compressed_chunks())

while not is_done():
    chunk = next(it)
    for uncompressed in uncompressed_chunks((chunk,))
        print(uncompressed)

print(num_bytes_unconsumed())

This can be useful in certain ZIP files.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc