MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / GettableMemory

Class GettableMemory

dwave/cloud/upload.py:209–237  ·  view source on GitHub ↗

Provide the :class:`Gettable` interface to a bytes-like object. Args: buf (bytes/bytearray/memoryview/bytes-like): Bytes-like object.

Source from the content-addressed store, hash-verified

207
208
209class GettableMemory(GettableBase):
210 """Provide the :class:`Gettable` interface to a bytes-like object.
211
212 Args:
213 buf (bytes/bytearray/memoryview/bytes-like):
214 Bytes-like object.
215
216 """
217
218 def __init__(self, buf):
219 self._buf = buf
220
221 def __len__(self):
222 return len(self._buf)
223
224 def getinto(self, key, buf):
225 start, stop, _ = self._getkey_to_range(key)
226
227 # empty slice
228 if stop <= start:
229 return 0
230
231 # copy source[start:stop] => target[0:stop-start]
232 source_view = self._buf[start:stop]
233 target_view = memoryview(buf)
234 size = min(len(source_view), len(target_view))
235 target_view[:size] = source_view[:size]
236
237 return size
238
239
240class FileView(io.RawIOBase):

Calls

no outgoing calls

Tested by 1