PyQvd icon indicating copy to clipboard operation
PyQvd copied to clipboard

from_stream requires seekable BinaryIO although documentation suggests generic stream support

Open MuellerConstantin opened this issue 8 months ago • 1 comments

Describe the bug The current implementation of QvdTable.from_stream() accepts a BinaryIO object, which suggests that any binary stream should work. However, the reader internally relies on seek() operations, meaning the input stream must actually be seekable.

As a result, passing non-seekable streams (e.g. S3 StreamingBody, HTTP response streams, pipes, or stdin) fails at runtime when the reader attempts to reposition the stream. This behavior contradicts the implied contract of accepting generic BinaryIO inputs.

To Reproduce Example using an S3 stream (non-seekable):

  1. Read a QVD file from S3 using boto3
  2. Pass the returned stream to from_stream()
import boto3
from pyqvd import QvdTable

s3 = boto3.client("s3")
obj = s3.get_object(Bucket="my-bucket", Key="sample.qvd")

tbl = QvdTable.from_stream(obj["Body"])
  1. The reader fails when a seek() call is executed internally.

Expected behavior from_stream() should either:

  • support non-seekable streams, or
  • explicitly require a seekable input and validate this early with a clear error message.

Given the current API (BinaryIO), the more natural expectation is that forward-only streams should be supported.

Additional context The reader currently requires seek() mainly in two places:

  • repositioning to the symbol table offset
  • reading chunks from the index table using offsets

Supporting non-seekable streams could be achieved by converting the reader to a sequential parsing model:

  • Read the header and detect the delimiter.
  • Preserve any bytes read past the delimiter as a buffer for the next stage.
  • Read the symbol table directly from the current stream position.
  • Parse the index table sequentially, decoding records as they are read rather than seeking to offsets.

This would allow the reader to operate on any forward-only stream while still supporting chunked iteration. If full support for non-seekable streams is not desired, the alternative would be to check stream.seekable() and raise a clear error explaining that the input must support random access.

MuellerConstantin avatar Mar 13 '26 11:03 MuellerConstantin

With regard to chunking, the following methods would primarily need to be renamed:

  • _parse_index_table_chunk to _parse_index_table_next_chunk
  • _read_index_table_chunk_data to _read_index_table_next_chunk_data

The signature would be def _read_index_table_next_chunk_data(self, chunk_size: int) -> bytes and def _parse_index_table_next_chunk(self, chunk_size: int) -> List[List[int]], and the property chunk_offset would be omitted, since it is read sequentially anyway.

MuellerConstantin avatar Mar 13 '26 11:03 MuellerConstantin