[New-bugs-announce] [issue35227] [RFE] tarfile: support adding file objects without prior known size

Michał Górny report at bugs.python.org
Tue Nov 13 03:27:56 EST 2018

New submission from Michał Górny <mgorny at gentoo.org>:

Currently, the tarfile module only supports adding files if their size is known prior to adding.  However, I think it'd be helpful to be able to store large dynamically generated streams straight into the (uncompressed) .tar file without being able to precalculate the final size and without having to use a temporary file.

I'm not really sure how the API should look like (i.e. whether it should be a new method or extension of addfile()) but the mechanism would be rather simple -- write TarInfo with size of 0, write data until end of stream, write padding appropriately to written data, seek back and update TarInfo.

Of course, the use of this API would have to be restricted to cases when underlying file supports seeking back and random writes, i.e. not stream, not compressed.

components: Library (Lib)
messages: 329818
nosy: mgorny
priority: normal
severity: normal
status: open
title: [RFE] tarfile: support adding file objects without prior known size
type: enhancement
versions: Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list