forked from zarr-developers/zarr-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodec.py
More file actions
119 lines (95 loc) · 2.78 KB
/
Copy pathcodec.py
File metadata and controls
119 lines (95 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from __future__ import annotations
from abc import abstractmethod
from typing import TYPE_CHECKING, Optional
import numpy as np
from zarr.abc.metadata import Metadata
from zarr.common import ArraySpec
from zarr.store import StorePath
if TYPE_CHECKING:
from typing_extensions import Self
from zarr.common import BytesLike, SliceSelection
from zarr.metadata import ArrayMetadata
from zarr.config import RuntimeConfiguration
class Codec(Metadata):
is_fixed_size: bool
@abstractmethod
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
pass
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
return chunk_spec
def evolve(self, array_spec: ArraySpec) -> Self:
return self
def validate(self, array_metadata: ArrayMetadata) -> None:
pass
class ArrayArrayCodec(Codec):
@abstractmethod
async def decode(
self,
chunk_array: np.ndarray,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> np.ndarray:
pass
@abstractmethod
async def encode(
self,
chunk_array: np.ndarray,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> Optional[np.ndarray]:
pass
class ArrayBytesCodec(Codec):
@abstractmethod
async def decode(
self,
chunk_array: BytesLike,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> np.ndarray:
pass
@abstractmethod
async def encode(
self,
chunk_array: np.ndarray,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> Optional[BytesLike]:
pass
class ArrayBytesCodecPartialDecodeMixin:
@abstractmethod
async def decode_partial(
self,
store_path: StorePath,
selection: SliceSelection,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> Optional[np.ndarray]:
pass
class ArrayBytesCodecPartialEncodeMixin:
@abstractmethod
async def encode_partial(
self,
store_path: StorePath,
chunk_array: np.ndarray,
selection: SliceSelection,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> None:
pass
class BytesBytesCodec(Codec):
@abstractmethod
async def decode(
self,
chunk_array: BytesLike,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> BytesLike:
pass
@abstractmethod
async def encode(
self,
chunk_array: BytesLike,
chunk_spec: ArraySpec,
runtime_configuration: RuntimeConfiguration,
) -> Optional[BytesLike]:
pass