diff --git a/pyproject.toml b/pyproject.toml index 231a8795..627f93f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "c2pa-python" -version = "0.32.11" +version = "0.32.12" requires-python = ">=3.10" description = "Python bindings for the C2PA Content Authenticity Initiative (CAI) library" readme = { file = "README.md", content-type = "text/markdown" } diff --git a/src/c2pa/c2pa.py b/src/c2pa/c2pa.py index 4ada020d..c33450dc 100644 --- a/src/c2pa/c2pa.py +++ b/src/c2pa/c2pa.py @@ -1812,7 +1812,17 @@ def read_callback(ctx, data, length): if not data or length <= 0: return -1 - buffer = self._file_like_stream.read(length) + stream = self._file_like_stream + readinto = getattr(stream, "readinto", None) + if readinto is not None: + # Most streams have readinto + buf = (ctypes.c_char * length).from_address( + ctypes.addressof(data.contents)) + n = readinto(buf) + return n if n else 0 + + # Fallback for streams without readinto. + buffer = stream.read(length) if not buffer: # EOF return 0 @@ -1846,8 +1856,10 @@ def seek_callback(ctx, offset, whence): if not self._initialized or self._closed: return -1 try: - file_stream.seek(offset, whence) - return file_stream.tell() + # Fall back to tell() only for stream objects that do not + # return the new absolute position and return None. + pos = file_stream.seek(offset, whence) + return pos if pos is not None else file_stream.tell() except Exception: return -1