Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/decoding/file_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def read(self, size: int) -> bytes:
self.num_reads += 1
return self._file.read(size)

def seek(self, offset: int, whence: int) -> bytes:
def seek(self, offset: int, whence: int) -> int:
self.num_seeks += 1
return self._file.seek(offset, whence)

Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/_audio_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AudioDecoder:
- If ``bytes`` object or ``torch.Tensor``: the raw encoded audio data.
- If file-like object: we read video data from the object on demand. The object must
expose the methods `read(self, size: int) -> bytes` and
`seek(self, offset: int, whence: int) -> bytes`. Read more in:
`seek(self, offset: int, whence: int) -> int`. Read more in:
:ref:`sphx_glr_generated_examples_decoding_file_like.py`.
stream_index (int, optional): Specifies which stream in the file to decode samples from.
Note that this index is absolute across all media types. If left unspecified, then
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/_decoder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def create_decoder(
f"Unknown source type: {type(source)}. "
"Supported types are str, Path, bytes, Tensor and file-like objects with "
"read(self, size: int) -> bytes and "
"seek(self, offset: int, whence: int) -> bytes methods."
"seek(self, offset: int, whence: int) -> int methods."
)
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/_video_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VideoDecoder:
- If ``bytes`` object or ``torch.Tensor``: the raw encoded video data.
- If file-like object: we read video data from the object on demand. The object must
expose the methods `read(self, size: int) -> bytes` and
`seek(self, offset: int, whence: int) -> bytes`. Read more in:
`seek(self, offset: int, whence: int) -> int`. Read more in:
:ref:`sphx_glr_generated_examples_decoding_file_like.py`.
stream_index (int, optional): Specifies which stream in the video to decode frames from.
Note that this index is absolute across all media types. If left unspecified, then
Expand Down
2 changes: 1 addition & 1 deletion test/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, file):
def read(self, size: int) -> bytes:
return self._file.read(size)

def seek(self, offset: int, whence: int) -> bytes:
def seek(self, offset: int, whence: int) -> int:
return self._file.seek(offset, whence)

source = CustomReader(open(asset.path, mode="rb", buffering=0))
Expand Down
16 changes: 8 additions & 8 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def read(self, size: int) -> bytes:
self.num_reads += 1
return self._file.read(size)

def seek(self, offset: int, whence: int) -> bytes:
def seek(self, offset: int, whence: int) -> int:
self.num_seeks += 1
return self._file.seek(offset, whence)

Expand Down Expand Up @@ -1086,8 +1086,8 @@ def seek(self, offset: int, whence: int) -> bytes:

def test_file_like_method_check_fails(self):
class ReadMethodMissing:
def seek(self, offset: int, whence: int) -> bytes:
return bytes()
def seek(self, offset: int, whence: int) -> int:
return 0

with pytest.raises(RuntimeError, match="must implement a read method"):
create_from_file_like(ReadMethodMissing(), "approximate")
Expand All @@ -1107,7 +1107,7 @@ def __init__(self, file: io.RawIOBase):
def read(self) -> bytes:
return bytes()

def seek(self, offset: int, whence: int) -> bytes:
def seek(self, offset: int, whence: int) -> int:
return self._file.seeK(offset, whence)

with pytest.raises(
Expand All @@ -1126,8 +1126,8 @@ def read(self, size: int) -> bytes:
return self._file.read(size)

# io.RawIOBase says we should accept two ints; wrong signature on purpose
def seek(self, offset: int) -> bytes:
return bytes()
def seek(self, offset: int) -> int:
return 0

with pytest.raises(
TypeError, match="takes 2 positional arguments but 3 were given"
Expand All @@ -1147,7 +1147,7 @@ def read(self, size: int) -> bytes:
# We intentionally read more than requested.
return self._file.read(size + 10)

def seek(self, offset: int, whence: int) -> bytes:
def seek(self, offset: int, whence: int) -> int:
return self._file.seek(offset, whence)

with pytest.raises(RuntimeError, match="does not conform to read protocol"):
Expand All @@ -1174,7 +1174,7 @@ def read(self, size: int) -> bytes:

return self._file.read(size)

def seek(self, offset: int, whence: int) -> bytes:
def seek(self, offset: int, whence: int) -> int:
return self._file.seek(offset, whence)

decoder_file_like = create_from_file_like(
Expand Down
Loading