in alibabacloud_oss_v2/filelike.py [0:0]
def _read_at(self, offset, n):
nodata_val = b""
empty_values = (b"")
if offset >= self._size_in_bytes:
return nodata_val
# Special case for when the number of bytes to read is unspecified.
if n is None or n < 0:
current_size = 0
chunks = []
while True:
chunk = self._next_chunk(offset + current_size)
if chunk is None:
continue
if chunk in empty_values:
nodata_val = chunk
break
current_size += len(chunk)
chunks.append(chunk)
return b"".join(chunks) or nodata_val
# The number of bytes to read is specified, return at most n bytes.
b = bytearray(n.__index__())
got = self._read_at_into(offset, b)
if got is None:
return None
del b[got:]
return bytes(b)