2019-03-20 19:49:47 +00:00
|
|
|
import gzip
|
|
|
|
import io
|
|
|
|
|
2019-03-21 23:48:13 +00:00
|
|
|
from .. import errors
|
2019-03-20 19:49:47 +00:00
|
|
|
|
|
|
|
|
2019-03-21 23:48:13 +00:00
|
|
|
name = "gzip"
|
2019-03-20 19:49:47 +00:00
|
|
|
|
2019-03-21 23:48:13 +00:00
|
|
|
def unpack_bytes(byte_data):
|
|
|
|
try:
|
|
|
|
buf = io.BytesIO(byte_data)
|
|
|
|
with gzip.GzipFile(mode='rb', fileobj=buf) as f:
|
|
|
|
unpacked = f.read()
|
|
|
|
except OSError as e:
|
|
|
|
raise errors.InvalidContainer(e)
|
|
|
|
return unpacked
|
|
|
|
|
|
|
|
|
|
|
|
def pack_bytes(media_container):
|
|
|
|
"""Pack the container using this packing algorithm
|
|
|
|
|
|
|
|
Return a byte string suitable to be written to disk
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|