diff --git a/doc/changelog.rst b/doc/changelog.rst index 4688a8fb65..4f4e5ace71 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,14 @@ Changelog ========= +Changes in Version 4.3.3 +------------------------ + +- Fixed a performance regression in :meth:`~gridfs.GridOut.download_to_stream` + and :meth:`~gridfs.GridOut.download_to_stream_by_name` by reading in chunks + instead of line by line. + + Changes in Version 4.3 (4.3.2) ------------------------------ diff --git a/gridfs/__init__.py b/gridfs/__init__.py index 6ab843a85e..692567b2de 100644 --- a/gridfs/__init__.py +++ b/gridfs/__init__.py @@ -796,7 +796,10 @@ def download_to_stream( Added ``session`` parameter. """ with self.open_download_stream(file_id, session=session) as gout: - for chunk in gout: + while True: + chunk = gout.readchunk() + if not len(chunk): + break destination.write(chunk) @_csot.apply @@ -977,7 +980,10 @@ def download_to_stream_by_name( Added ``session`` parameter. """ with self.open_download_stream_by_name(filename, revision, session=session) as gout: - for chunk in gout: + while True: + chunk = gout.readchunk() + if not len(chunk): + break destination.write(chunk) def rename(