edq.util.gzip
1import gzip 2 3import edq.util.dirent 4import edq.util.encoding 5 6def uncompress_base64(b64_contents: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> bytes: 7 """ Uncompress base64 encoded gzipped bytes into bytes. """ 8 9 contents = edq.util.encoding.from_base64(b64_contents, encoding = encoding) 10 return uncompress(contents) 11 12def uncompress_base64_to_path(b64_contents: str, path: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> None: 13 """ Uncompress base64 encoded gzipped bytes into a file. """ 14 15 contents = uncompress_base64(b64_contents, encoding) 16 edq.util.dirent.write_file_bytes(path, contents) 17 18def uncompress_base64_to_string(b64_contents: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 19 """ Uncompress base64 encoded gzipped bytes into a string. """ 20 21 return uncompress_base64(b64_contents, encoding).decode(encoding) 22 23def uncompress(data: bytes) -> bytes: 24 """ Uncompress gzipped bytes into bytes. """ 25 26 return gzip.decompress(data) 27 28def uncompress_to_path(data: bytes, path: str) -> None: 29 """ Uncompress gzipped bytes into a file. """ 30 31 contents = uncompress(data) 32 edq.util.dirent.write_file_bytes(path, contents) 33 34def uncompress_to_string(data: bytes, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 35 """ Uncompress gzipped bytes into a string. """ 36 37 return uncompress(data).decode(encoding) 38 39def compress_as_base64(raw_data: bytes, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 40 """ Get the compressed representation of some bytes as a base64 encoded string. """ 41 42 data = compress(raw_data) 43 return edq.util.encoding.to_base64(data, encoding = encoding) 44 45def compress(raw_data: bytes) -> bytes: 46 """ Get the compressed representation of some bytes as bytes. """ 47 48 return gzip.compress(raw_data) 49 50def compress_path_as_base64(path: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 51 """ Get the compressed contents of a file as a base64 encoded string. """ 52 53 data = compress_path(path) 54 return edq.util.encoding.to_base64(data, encoding = encoding) 55 56def compress_path(path: str) -> bytes: 57 """ Get the compressed contents of a file as bytes. """ 58 59 data = edq.util.dirent.read_file_bytes(path) 60 return gzip.compress(data)
def
uncompress_base64(b64_contents: str, encoding: str = 'utf-8') -> bytes:
7def uncompress_base64(b64_contents: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> bytes: 8 """ Uncompress base64 encoded gzipped bytes into bytes. """ 9 10 contents = edq.util.encoding.from_base64(b64_contents, encoding = encoding) 11 return uncompress(contents)
Uncompress base64 encoded gzipped bytes into bytes.
def
uncompress_base64_to_path(b64_contents: str, path: str, encoding: str = 'utf-8') -> None:
13def uncompress_base64_to_path(b64_contents: str, path: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> None: 14 """ Uncompress base64 encoded gzipped bytes into a file. """ 15 16 contents = uncompress_base64(b64_contents, encoding) 17 edq.util.dirent.write_file_bytes(path, contents)
Uncompress base64 encoded gzipped bytes into a file.
def
uncompress_base64_to_string(b64_contents: str, encoding: str = 'utf-8') -> str:
19def uncompress_base64_to_string(b64_contents: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 20 """ Uncompress base64 encoded gzipped bytes into a string. """ 21 22 return uncompress_base64(b64_contents, encoding).decode(encoding)
Uncompress base64 encoded gzipped bytes into a string.
def
uncompress(data: bytes) -> bytes:
24def uncompress(data: bytes) -> bytes: 25 """ Uncompress gzipped bytes into bytes. """ 26 27 return gzip.decompress(data)
Uncompress gzipped bytes into bytes.
def
uncompress_to_path(data: bytes, path: str) -> None:
29def uncompress_to_path(data: bytes, path: str) -> None: 30 """ Uncompress gzipped bytes into a file. """ 31 32 contents = uncompress(data) 33 edq.util.dirent.write_file_bytes(path, contents)
Uncompress gzipped bytes into a file.
def
uncompress_to_string(data: bytes, encoding: str = 'utf-8') -> str:
35def uncompress_to_string(data: bytes, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 36 """ Uncompress gzipped bytes into a string. """ 37 38 return uncompress(data).decode(encoding)
Uncompress gzipped bytes into a string.
def
compress_as_base64(raw_data: bytes, encoding: str = 'utf-8') -> str:
40def compress_as_base64(raw_data: bytes, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 41 """ Get the compressed representation of some bytes as a base64 encoded string. """ 42 43 data = compress(raw_data) 44 return edq.util.encoding.to_base64(data, encoding = encoding)
Get the compressed representation of some bytes as a base64 encoded string.
def
compress(raw_data: bytes) -> bytes:
46def compress(raw_data: bytes) -> bytes: 47 """ Get the compressed representation of some bytes as bytes. """ 48 49 return gzip.compress(raw_data)
Get the compressed representation of some bytes as bytes.
def
compress_path_as_base64(path: str, encoding: str = 'utf-8') -> str:
51def compress_path_as_base64(path: str, encoding: str = edq.util.dirent.DEFAULT_ENCODING) -> str: 52 """ Get the compressed contents of a file as a base64 encoded string. """ 53 54 data = compress_path(path) 55 return edq.util.encoding.to_base64(data, encoding = encoding)
Get the compressed contents of a file as a base64 encoded string.
def
compress_path(path: str) -> bytes:
57def compress_path(path: str) -> bytes: 58 """ Get the compressed contents of a file as bytes. """ 59 60 data = edq.util.dirent.read_file_bytes(path) 61 return gzip.compress(data)
Get the compressed contents of a file as bytes.