Changaco / python-libarchive-c

Python interface to libarchive
Other
70 stars 37 forks source link

Obtaining the position (byte offset) of an entry within the archive #112

Closed Changaco closed 2 years ago

Changaco commented 3 years ago

See https://github.com/Legilibre/legi.py/pull/83 for context.

Changaco commented 3 years ago

The standard tell method can be used to estimate how much of an archive has been processed. Here's an example of a progress bar using tqdm:

with tqdm(total=os.stat(archive_path).st_size, unit='bytes') as pbar, \
     open(archive_path, 'rb') as file, \
     libarchive.stream_reader(file) as archive:
    for entry in archive:
        ...
        pbar.update(file.tell() - pbar.n)