Skip to content

Commit 972b254

Browse files
committed
uncompressed oci image layers support added for make-rootfs action
1 parent 8351d8d commit 972b254

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/_actions/make_rootfs/_oci_image/_fake.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _open_blob_reader(digest: str, source: _SourceReader, size: int):
7474
assert isinstance(size, int)
7575
_path = _parse_digest(value = digest).path
7676
with source.open(_path) as _stream:
77-
with _make_size_guarantee(source = _stream, exact = size) as _guarantee: yield _guarantee
77+
with _make_size_guarantee(source = _stream, limit = size) as _guarantee: yield _guarantee
7878

7979
@contextlib.contextmanager
8080
def _open_blob_writer(image: str):
@@ -105,10 +105,11 @@ def _validate_layer_media_type(value: str):
105105
assert value
106106
assert value.startswith(_layer_media_type_begin)
107107
_value = value[_layer_media_type_minimum_size:]
108-
if not _value: return value
109-
assert "+" == _value[0]
110-
_value = _value[1:]
111-
assert _value in {"gzip", "bzip"}
108+
if _value:
109+
assert "+" == _value[0]
110+
_value = _value[1:]
111+
assert _value in {"gzip", "bzip"}
112+
return value
112113

113114
def _read_bundle(manifest: dict, source: _SourceReader):
114115
assert isinstance(manifest, dict)

src/_actions/make_rootfs/_oci_image/_size_guarantee.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,34 @@ def left(self): return self.__left
1414

1515
def tell(self, *args, **kwargs): return self.__stream.tell(*args, **kwargs)
1616

17+
def seek(self, *args, **kwargs):
18+
try: return self.__stream.seek(*args, **kwargs)
19+
finally: self.__finally()
20+
1721
def read(self, *args, **kwargs):
18-
_chunk = self.__stream.read(*args, **kwargs)
19-
assert isinstance(_chunk, (str, bytes))
20-
_size = len(_chunk)
21-
if 0 < _size:
22-
assert self.__left >= _size
23-
self.__left -= _size
24-
return _chunk
22+
try: return self.__stream.read(*args, **kwargs)
23+
finally: self.__finally()
2524

2625
def __init__(self, stream, size: int):
2726
super().__init__()
2827
assert isinstance(size, int)
2928
assert 0 < size
29+
_begin = stream.tell()
30+
self.__end = size + _begin
3031
self.__left = size
32+
self.__begin = _begin
3133
self.__stream = stream
3234

35+
def __finally(self):
36+
_position = self.__stream.tell()
37+
38+
try:
39+
assert self.__begin <= _position
40+
assert self.__end >= _position
41+
finally:
42+
_position = max(self.__begin, min(self.__end, _position))
43+
self.__left = min(self.__left, self.__end - _position)
44+
3345
@contextlib.contextmanager
3446
def _data_wrapper(source: typing.Union[str, bytes], limit: typing.Optional[int], exact: typing.Optional[int]):
3547
assert isinstance(source, (str, bytes))
@@ -55,10 +67,13 @@ def _stream_wrapper(source, limit: typing.Optional[int], exact: typing.Optional[
5567

5668
class _Class(object):
5769
@staticmethod
58-
def read(*args, **kwargs): return _helper.read(*args, **kwargs)
70+
def tell(*args, **kwargs): return _helper.tell(*args, **kwargs)
5971

6072
@staticmethod
61-
def tell(*args, **kwargs): return _helper.tell(*args, **kwargs)
73+
def seek(*args, **kwargs): return _helper.seek(*args, **kwargs)
74+
75+
@staticmethod
76+
def read(*args, **kwargs): return _helper.read(*args, **kwargs)
6277

6378
yield _Class()
6479
assert (exact is None) or (0 == _helper.left)

src/_actions/make_rootfs/_oci_image/bundle/_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _open_layers(meta: typing.Iterable[dict], source: _SourceReader):
100100
assert isinstance(_layer, dict)
101101
_media = _layer["mediaType"]
102102
assert isinstance(_media, str)
103-
assert "application/vnd.oci.image.layer.v1.tar+gzip" == _media
103+
assert _media in {"application/vnd.oci.image.layer.v1.tar", "application/vnd.oci.image.layer.v1.tar+gzip"}
104104
_size = _layer["size"]
105105
assert isinstance(_size, int)
106106
assert 0 < _size

0 commit comments

Comments
 (0)