Last active
August 29, 2015 14:23
-
-
Save Suor/4d6bb599a5f3c367c432 to your computer and use it in GitHub Desktop.
Ungzip stream on the fly in Python 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gzip, zlib | |
def ungzip_stream(fd): | |
plain_fd = gzip.GzipFile(fileobj=fd, mode="r") | |
# NOTE: this is what GzipFile does on new file start, | |
# we do that directly as GzipFile tries to seek() before it | |
# and fd could be unseekable(). | |
plain_fd._init_read() | |
plain_fd._read_gzip_header() | |
plain_fd.decompress = zlib.decompressobj(-zlib.MAX_WBITS) | |
plain_fd._new_member = False | |
return plain_fd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't always work, I wrote proper solution.