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)
| 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 | |
| 209 | class GettableMemory(GettableBase): |
nothing calls this directly
no test coverage detected