Skip to content

Commit

Permalink
Removed code duplication between podman_container and docker_container.
Browse files Browse the repository at this point in the history
This work is needed to improve maintainability of both, as they
share the same code to compress saved images on the fly,
and decompress on the fly container images being loaded into the
local registry.

Also, switched container image compression from lzma to pgzip.
Images are bigger, but the parallelized version of gzip library
is much faster.
  • Loading branch information
jmfernandez committed Sep 5, 2023
1 parent 5c3720c commit b2e807d
Show file tree
Hide file tree
Showing 7 changed files with 466 additions and 401 deletions.
8 changes: 8 additions & 0 deletions mypy-stubs/pgzip/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .pgzip import (
PgzipFile,
compress as compress,
decompress as decompress,
open as open,
)

GzipFile = PgzipFile
93 changes: 93 additions & 0 deletions mypy-stubs/pgzip/pgzip.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from concurrent.futures import (
Future,
ThreadPoolExecutor,
)
from gzip import GzipFile, _GzipReader
from io import FileIO
from typing import (
Any,
IO,
Iterable,
MutableSequence,
Optional,
Sequence,
Tuple,
)
from typing_extensions import (
Buffer,
Literal,
)
import zlib

SID: bytes

def open(
filename: str,
mode: str = ...,
compresslevel: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
thread: Optional[int] = ...,
blocksize: int = ...,
) -> IO[bytes]: ...
def compress(
data: bytes,
compresslevel: int = ...,
thread: Optional[int] = ...,
blocksize: int = ...,
) -> bytes: ...
def decompress(
data: bytes, thread: Optional[int] = ..., blocksize: int = ...
) -> bytes: ...
def padded_file_seek(self: PgzipFile, off: int, whence: int = ...) -> int: ...

class PgzipFile(GzipFile):
thread: int
read_blocks: Optional[Any]
mode: Literal[1, 2]
raw: _MulitGzipReader
name: str
index: MutableSequence[MutableSequence[int]]
compress: zlib._Compress
compresslevel: int
blocksize: int
pool: ThreadPoolExecutor
pool_result: MutableSequence[Future[Tuple[bytes, bytes, bytes, int, int]]]
small_buf: IO[bytes]
fileobj: IO[bytes]
def __init__(
self,
filename: Optional[str] = ...,
mode: Optional[str] = ...,
compresslevel: int = ...,
fileobj: Optional[IO[bytes]] = ...,
mtime: Optional[float] = ...,
thread: Optional[int] = ...,
blocksize: int = ...,
) -> None: ...
def write(self, data: Buffer) -> int: ...
def get_index(self) -> MutableSequence[MutableSequence[int]]: ...
def show_index(self) -> None: ...
def build_index(
self, idx_file: Optional[str] = ...
) -> MutableSequence[MutableSequence[int]]: ...
def load_index(self, idx_file: str) -> MutableSequence[MutableSequence[int]]: ...
def set_read_blocks(self, block_ids: Sequence[int]) -> None: ...
def set_read_blocks_by_name(self, block_names: Sequence[str]) -> None: ...
def clear_read_blocks(self) -> None: ...
myfileobj: FileIO
def close(self) -> None: ...
def flush(self, zlib_mode: int = ...) -> None: ...

class _MulitGzipReader(_GzipReader):
memberidx: MutableSequence[Tuple[int, int]]
max_block_size: int
thread: int
block_start_iter: Optional[Iterable[int]]
def __init__(
self, fp: Any, thread: int = ..., max_block_size: int = ...
) -> None: ...
def read(self, size: int = ...) -> bytes: ...
def set_block_iter(self, block_start_list: Sequence[int]) -> None: ...
def clear_block_iter(self) -> None: ...
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ rocrate >= 0.7.0
boto3
botocore
google-cloud-storage
typing_extensions
pyncclient-ext >= 0.1.2
wiktionary-term-fetcher >= 0.1.1
funny-passphrase >= 0.2.3
pyxdg
groovy-parser == 0.1.1
data-url
data-url
pgzip
Loading

0 comments on commit b2e807d

Please sign in to comment.