Skip to main content

Fast random access to bzip2 files

Project description

indexed_bzip2

PyPI version Downloads License Build Status codecov

This module provides an IndexedBzip2File class, which can be used to seek inside bzip2 files without having to decompress them first. It's based on an improved version of the bzip2 decoder bzcat from toybox, which was refactored and extended to be able to export and import bzip2 block offsets and seek to them and to add support for threaded parallel decoding of blocks.

Seeking inside a block is only emulated, so IndexedBzip2File will only speed up seeking when there are more than one block, which should almost always be the cause for archives larger than 1 MB.

Since version 1.2.0, parallel decoding of blocks is supported! Per default, the older serial implementation is used. To use the parallel implementation you need to specify a parallelization other than 1 argument to IndexedBzip2File.

Installation

You can simply install it from PyPI:

pip install indexed_bzip2

Usage

Example 1

from indexed_bzip2 import IndexedBzip2File

file = IndexedBzip2File( "example.bz2", parallelization = os.cpu_count() )

# You can now use it like a normal file
file.seek( 123 )
data = file.read( 100 )

The first call to seek will ensure that the block offset list is complete and therefore might create them first. Because of this the first call to seek might take a while.

Example 2

The creation of the list of bzip2 blocks can take a while because it has to decode the bzip2 file completely. To avoid this setup when opening a bzip2 file, the block offset list can be exported and imported.

from indexed_bzip2 import IndexedBzip2File
import pickle

# Calculate and save bzip2 block offsets
file = IndexedBzip2File( "example.bz2", parallelization = os.cpu_count() )
block_offsets = file.block_offsets() # can take a while
# block_offsets is a simple dictionary where the keys are the bzip2 block offsets in bits(!)
# and the values are the corresponding offsets in the decoded data in bytes. E.g.:
# block_offsets = {32: 0, 14920: 4796}
with open( "offsets.dat", 'wb' ) as offsets_file:
    pickle.dump( block_offsets, offsets_file )
file.close()

# Load bzip2 block offsets for fast seeking
with open( "offsets.dat", 'rb' ) as offsets_file:
    block_offsets = pickle.load( offsets_file )
file2 = IndexedBzip2File( "example.bz2", parallelization = os.cpu_count() )
file2.set_block_offsets( block_offsets ) # should be fast
file2.seek( 123 )
data = file2.read( 100 )
file2.close()

Tracing the decoder

Performance profiling and tracing is done with Score-P for instrumentation and Vampir for visualization. This is one way, you could install Score-P with most of the functionalities on Debian 10.

# Install PAPI
wget http://icl.utk.edu/projects/papi/downloads/papi-5.7.0.tar.gz
tar -xf papi-5.7.0.tar.gz
cd papi-5.7.0/src
./configure
make -j
sudo make install

# Install Dependencies
sudo apt-get install libopenmpi-dev openmpi gcc-8-plugin-dev llvm-dev libclang-dev libunwind-dev libopen-trace-format-dev otf-trace

# Install Score-P (to /opt/scorep)
wget https://www.vi-hps.org/cms/upload/packages/scorep/scorep-6.0.tar.gz
tar -xf scorep-6.0.tar.gz
cd scorep-6.0
./configure --with-mpi=openmpi --enable-shared
make -j
make install

# Add /opt/scorep to your path variables on shell start
cat <<EOF >> ~/.bashrc
if test -d /opt/scorep; then
    export SCOREP_ROOT=/opt/scorep
    export PATH=$SCOREP_ROOT/bin:$PATH
    export LD_LIBRARY_PATH=$SCOREP_ROOT/lib:$LD_LIBRARY_PATH
fi
EOF

# Check whether it works
scorep --version
scorep-info config-summary

# Actually do the tracing
cd tools
bash trace.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

indexed_bzip2-1.2.0.tar.gz (101.0 kB view hashes)

Uploaded Source

Built Distributions

indexed_bzip2-1.2.0-pp37-pypy37_pp73-win_amd64.whl (88.3 kB view hashes)

Uploaded PyPy Windows x86-64

indexed_bzip2-1.2.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (172.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

indexed_bzip2-1.2.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (182.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

indexed_bzip2-1.2.0-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (159.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

indexed_bzip2-1.2.0-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (169.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686

indexed_bzip2-1.2.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (101.0 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

indexed_bzip2-1.2.0-cp310-cp310-win_amd64.whl (92.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

indexed_bzip2-1.2.0-cp310-cp310-win32.whl (82.0 kB view hashes)

Uploaded CPython 3.10 Windows x86

indexed_bzip2-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

indexed_bzip2-1.2.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

indexed_bzip2-1.2.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64

indexed_bzip2-1.2.0-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686

indexed_bzip2-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl (118.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

indexed_bzip2-1.2.0-cp39-cp39-win_amd64.whl (92.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

indexed_bzip2-1.2.0-cp39-cp39-win32.whl (82.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

indexed_bzip2-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

indexed_bzip2-1.2.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

indexed_bzip2-1.2.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

indexed_bzip2-1.2.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

indexed_bzip2-1.2.0-cp39-cp39-macosx_10_9_x86_64.whl (118.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

indexed_bzip2-1.2.0-cp38-cp38-win_amd64.whl (92.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

indexed_bzip2-1.2.0-cp38-cp38-win32.whl (81.9 kB view hashes)

Uploaded CPython 3.8 Windows x86

indexed_bzip2-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

indexed_bzip2-1.2.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

indexed_bzip2-1.2.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

indexed_bzip2-1.2.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

indexed_bzip2-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl (118.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

indexed_bzip2-1.2.0-cp37-cp37m-win_amd64.whl (91.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

indexed_bzip2-1.2.0-cp37-cp37m-win32.whl (81.5 kB view hashes)

Uploaded CPython 3.7m Windows x86

indexed_bzip2-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

indexed_bzip2-1.2.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

indexed_bzip2-1.2.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

indexed_bzip2-1.2.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

indexed_bzip2-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl (117.8 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

indexed_bzip2-1.2.0-cp36-cp36m-win_amd64.whl (91.6 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

indexed_bzip2-1.2.0-cp36-cp36m-win32.whl (81.5 kB view hashes)

Uploaded CPython 3.6m Windows x86

indexed_bzip2-1.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

indexed_bzip2-1.2.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

indexed_bzip2-1.2.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

indexed_bzip2-1.2.0-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

indexed_bzip2-1.2.0-cp36-cp36m-macosx_10_9_x86_64.whl (117.8 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page