targzstream
Version: 1.1
Summary
This module provides an extension to the standard tarfile.TarFile class which provides the ability to add files to a TarFile that are compressed on-the-fly. It will only work on an uncompressed output tarfile, since after the data is written it will overwrite the header for the file with the correct size data.
Limitations
The object to which the tarfile is being written must support “seek()”, so this cannot work over a socket, nor presumably with a compressed tarfile. Note: re-compressing contents is not very useful.
The “close_gz_file” method will be called when calling “close” on the file stream. Note: close_gz_file() and close_file() are interchangeable.
The constructor does not support reading, use the open() class method or use the base class tarfile.TarFile constructor.
Example Usage
#!/usr/bin/env python3
import os, sys, shutil
import targzstream
# USAGE: ./foo.py TARFILE INPUT [ INPUT2 ... ]
# Eg: ./foo.py myoutput.tar *.cpp *.h
with targzstream.TarFile(sys.argv[1], mode='w') as tarball:
for fname in sys.argv[2:]:
st = os.stat(fname)
with tarball.add_gz_file(name=fname + '.gz', mtime=st.st_mtime,
uid=st.st_uid, gid=st.st_gid, mode=st.st_mode) as fout:
# Copy the data.
with open(fname, 'rb') as fin:
shutil.copyfileobj(fin, fout)
# The end.
TODO
Have add_gz_file handle the result of an os.stat. Eg:
with tarball.gz_file(name=fname + '.gz', stat=os.stat(fname)) as obj: with open(fname, 'rb') as fin: shutil.copyfileobj(fin, obj)Wrap add_gz_file and close_gz_file as a context manager.
Done.
Allow streaming uncompressed files, too.
Done.
Metadata
Release files for targzstream 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| targzstream-1.1.tar.gz | 3.8 kB | Without provenance | Details for targzstream-1.1.tar.gz |
Release files / targzstream-1.1.tar.gz
| Download URL | targzstream-1.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a1590674ae677c7e23cd3bb7f3961f9a10771474fe96635f3c02e87761b3c5b7
|
|
BLAKE2b-256 checksum How to use checksums |
1190bfaf25c10cc779f644d421fd705d21b3bc169bcb797d3aa568a3b7eb57af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for targzstream 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.