diff --git a/b2sdk/_internal/transfer/inbound/downloaded_file.py b/b2sdk/_internal/transfer/inbound/downloaded_file.py index 7242b19df..64591bddf 100644 --- a/b2sdk/_internal/transfer/inbound/downloaded_file.py +++ b/b2sdk/_internal/transfer/inbound/downloaded_file.py @@ -274,6 +274,12 @@ def save_to( try: with context as file: return self.save(file, allow_seeking=allow_seeking) + except BrokenPipeError as ex: + if is_stdout: + # Output was likely piped through a command such as head. Just ignore the error + return + else: + raise ex finally: if not is_stdout: set_file_mtime(path_, self.download_version.mod_time_millis) diff --git a/changelog.d/534.fixed.md b/changelog.d/534.fixed.md new file mode 100644 index 000000000..0555f496b --- /dev/null +++ b/changelog.d/534.fixed.md @@ -0,0 +1 @@ +Suppress BrokenPipeError when saving downloaded content to stdout.