Skip to content

Make shutil.make_archive and unpack_archive support file-like objects #103397

Open
@nickovs

Description

@nickovs

Feature or enhancement

The underlying tarfile.open() and zipfile.ZipFile() functions used by shutil.make_archive() and shutil. unpack_archive () both support passing a file descriptor or file-like object instead of a file name. It would be helpful if their shutil wrappers also supported this behaviour.

Pitch

There are several cases where it is helpful to be able to stream an archive in from or out to a file descriptor or file-like object. For instance if the storage for the archive is not local and it needs to be sent across a network, both latency and temporary storage are reduced if the network IO can happen in parallel to the archival process. It is also valuable when the process creating the archive has limited access to writable storage (either due to permissions or due to limited writable space) so storing a temporary copy of the archive is problematic. In general this feature is useful for all the same reasons that tarfile.open() and zipfile.ZipFile() accept file descriptors.

While the shutil module is generally about "files", and so operations using file descriptors instead of filenames may seem counter-intuitive, the archive creation and unpacking is still operating on directories full of files and so it still makes sense to support this use case in shutil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions