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

Method getinto

dwave/cloud/upload.py:178–206  ·  view source on GitHub ↗

Copy a slice of file's content into a pre-allocated bytes-like object buf. For example, buf might be a `bytearray`. Args: key (slice/int): Source data address coded as a `slice` object or int position. buf (bytes-like): Target

(self, key, buf)

Source from the content-addressed store, hash-verified

176 return self._size
177
178 def getinto(self, key, buf):
179 """Copy a slice of file's content into a pre-allocated bytes-like
180 object buf. For example, buf might be a `bytearray`.
181
182 Args:
183 key (slice/int):
184 Source data address coded as a `slice` object or int position.
185 buf (bytes-like):
186 Target pre-allocated bytes-like object.
187
188 Returns:
189 int:
190 The number of bytes read (0 for EOF).
191 """
192
193 start, stop, _ = self._getkey_to_range(key)
194
195 # empty slice
196 if stop <= start:
197 return 0
198
199 # copy source[start:stop] => target[0:stop-start]
200 size = stop - start
201 target = memoryview(buf)[:size]
202
203 # slice is an atomic "seek and read" operation
204 with self._lock:
205 self._fp.seek(start)
206 return self._fp.readinto(target)
207
208
209class GettableMemory(GettableBase):

Callers

nothing calls this directly

Calls 3

_getkey_to_rangeMethod · 0.80
seekMethod · 0.80
readintoMethod · 0.80

Tested by

no test coverage detected