|
5 | 5 | from enum import Enum |
6 | 6 | from typing import TYPE_CHECKING |
7 | 7 |
|
8 | | -from zarr.abc.codec import ArrayBytesCodec, PreparedWrite, SupportsChunkCodec |
| 8 | +from zarr.abc.codec import ArrayBytesCodec |
9 | 9 | from zarr.core.buffer import Buffer, NDBuffer |
10 | 10 | from zarr.core.common import JSON, parse_enum, parse_named_configuration |
11 | 11 | from zarr.core.dtype.common import HasEndianness |
12 | 12 |
|
13 | 13 | if TYPE_CHECKING: |
14 | | - from typing import Any, Self |
| 14 | + from typing import Self |
15 | 15 |
|
16 | 16 | from zarr.core.array_spec import ArraySpec |
17 | | - from zarr.core.indexing import SelectorTuple |
18 | 17 |
|
19 | 18 |
|
20 | 19 | class Endian(Enum): |
@@ -126,114 +125,3 @@ async def _encode_single( |
126 | 125 |
|
127 | 126 | def compute_encoded_size(self, input_byte_length: int, _chunk_spec: ArraySpec) -> int: |
128 | 127 | return input_byte_length |
129 | | - |
130 | | - # -- SupportsChunkMapping -- |
131 | | - |
132 | | - @property |
133 | | - def inner_codec_chain(self) -> SupportsChunkCodec | None: |
134 | | - """Returns `None` — the pipeline should use its own codec chain.""" |
135 | | - return None |
136 | | - |
137 | | - def unpack_chunks( |
138 | | - self, |
139 | | - raw: Buffer | None, |
140 | | - chunk_spec: ArraySpec, |
141 | | - ) -> dict[tuple[int, ...], Buffer | None]: |
142 | | - """Single chunk keyed at `(0,)`.""" |
143 | | - return {(0,): raw} |
144 | | - |
145 | | - def pack_chunks( |
146 | | - self, |
147 | | - chunk_dict: dict[tuple[int, ...], Buffer | None], |
148 | | - chunk_spec: ArraySpec, |
149 | | - ) -> Buffer | None: |
150 | | - """Return the single chunk's bytes.""" |
151 | | - return chunk_dict.get((0,)) |
152 | | - |
153 | | - def prepare_read_sync( |
154 | | - self, |
155 | | - byte_getter: Any, |
156 | | - chunk_selection: SelectorTuple, |
157 | | - codec_chain: SupportsChunkCodec, |
158 | | - ) -> NDBuffer | None: |
159 | | - """Fetch, decode, and return the selected region synchronously.""" |
160 | | - raw = byte_getter.get_sync(prototype=codec_chain.array_spec.prototype) |
161 | | - if raw is None: |
162 | | - return None |
163 | | - chunk_array = codec_chain.decode_chunk(raw) |
164 | | - return chunk_array[chunk_selection] |
165 | | - |
166 | | - def prepare_write_sync( |
167 | | - self, |
168 | | - byte_setter: Any, |
169 | | - codec_chain: SupportsChunkCodec, |
170 | | - chunk_selection: SelectorTuple, |
171 | | - out_selection: SelectorTuple, |
172 | | - replace: bool, |
173 | | - ) -> PreparedWrite: |
174 | | - """Fetch existing data if needed, unpack, return `PreparedWrite`.""" |
175 | | - from zarr.core.indexing import ChunkProjection |
176 | | - |
177 | | - existing: Buffer | None = None |
178 | | - if not replace: |
179 | | - existing = byte_setter.get_sync(prototype=codec_chain.array_spec.prototype) |
180 | | - chunk_dict = self.unpack_chunks(existing, codec_chain.array_spec) |
181 | | - indexer = [ChunkProjection((0,), chunk_selection, out_selection, replace)] # type: ignore[arg-type] |
182 | | - return PreparedWrite(chunk_dict=chunk_dict, indexer=indexer) |
183 | | - |
184 | | - def finalize_write_sync( |
185 | | - self, |
186 | | - prepared: PreparedWrite, |
187 | | - chunk_spec: ArraySpec, |
188 | | - byte_setter: Any, |
189 | | - ) -> None: |
190 | | - """Pack and write to store, or delete if empty.""" |
191 | | - blob = self.pack_chunks(prepared.chunk_dict, chunk_spec) |
192 | | - if blob is None: |
193 | | - byte_setter.delete_sync() |
194 | | - else: |
195 | | - byte_setter.set_sync(blob) |
196 | | - |
197 | | - async def prepare_read( |
198 | | - self, |
199 | | - byte_getter: Any, |
200 | | - chunk_selection: SelectorTuple, |
201 | | - codec_chain: SupportsChunkCodec, |
202 | | - ) -> NDBuffer | None: |
203 | | - """Async variant of `prepare_read_sync`.""" |
204 | | - raw = await byte_getter.get(prototype=codec_chain.array_spec.prototype) |
205 | | - if raw is None: |
206 | | - return None |
207 | | - chunk_array = codec_chain.decode_chunk(raw) |
208 | | - return chunk_array[chunk_selection] |
209 | | - |
210 | | - async def prepare_write( |
211 | | - self, |
212 | | - byte_setter: Any, |
213 | | - codec_chain: SupportsChunkCodec, |
214 | | - chunk_selection: SelectorTuple, |
215 | | - out_selection: SelectorTuple, |
216 | | - replace: bool, |
217 | | - ) -> PreparedWrite: |
218 | | - """Async variant of `prepare_write_sync`.""" |
219 | | - from zarr.core.indexing import ChunkProjection |
220 | | - |
221 | | - existing: Buffer | None = None |
222 | | - if not replace: |
223 | | - existing = await byte_setter.get(prototype=codec_chain.array_spec.prototype) |
224 | | - chunk_dict = self.unpack_chunks(existing, codec_chain.array_spec) |
225 | | - indexer = [ChunkProjection((0,), chunk_selection, out_selection, replace)] # type: ignore[arg-type] |
226 | | - return PreparedWrite(chunk_dict=chunk_dict, indexer=indexer) |
227 | | - |
228 | | - async def finalize_write( |
229 | | - self, |
230 | | - prepared: PreparedWrite, |
231 | | - chunk_spec: ArraySpec, |
232 | | - byte_setter: Any, |
233 | | - ) -> None: |
234 | | - """Async variant of `finalize_write_sync`.""" |
235 | | - blob = self.pack_chunks(prepared.chunk_dict, chunk_spec) |
236 | | - if blob is None: |
237 | | - await byte_setter.delete() |
238 | | - else: |
239 | | - await byte_setter.set(blob) |
0 commit comments