1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-30 19:46:25 +00:00
bazarr/libs/subzero/lib/geezip.py
Louis Vézina 3ca2c98cd4 WIP
2019-09-16 22:04:27 -04:00

38 lines
1 KiB
Python

# coding=utf-8
from __future__ import absolute_import
import gzip
from zlib import Z_FINISH
__all__ = ["GeezipFile", "open", "Z_FINISH"]
def open(filename, mode="rb", compresslevel=9):
"""Shorthand for GzipFile(filename, mode, compresslevel).
The filename argument is required; mode defaults to 'rb'
and compresslevel defaults to 9.
"""
return GeezipFile(filename, mode, compresslevel)
class GeezipFile(gzip.GzipFile):
def close(self):
fileobj = self.fileobj
if fileobj is None:
return
self.fileobj = None
try:
if self.mode == gzip.WRITE:
fileobj.write(self.compress.flush(Z_FINISH))
gzip.write32u(fileobj, self.crc)
# self.size may exceed 2GB, or even 4GB
gzip.write32u(fileobj, self.size & 0xffffffff)
fileobj.flush()
finally:
myfileobj = self.myfileobj
if myfileobj:
self.myfileobj = None
myfileobj.close()