### Install rapidgzip from PyPI Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Installs the rapidgzip command-line tool and Python library using pip. It first upgrades pip and then installs rapidgzip. Finally, it shows how to verify the installation by checking the help and version information. ```bash python3 -m pip install --upgrade pip python3 -m pip install rapidgzip rapidgzip --help rapidgzip --version ``` -------------------------------- ### Install Score-P Dependencies and Score-P Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Installs necessary development libraries for Score-P using apt-get, downloads and installs Score-P from a tarball, and configures environment variables for its use. It also adjusts kernel parameters for performance monitoring and verifies the installation. ```bash sudo apt-get install libopenmpi-dev openmpi-bin gcc-11-plugin-dev llvm-dev libclang-dev libunwind-dev \ libopen-trace-format-dev otf-trace libpapi-dev # Install Score-P (to /opt/scorep) SCOREP_VERSION=8.0 wget "https://perftools.pages.jsc.fz-juelich.de/cicd/scorep/tags/scorep-${SCOREP_VERSION}/scorep-${SCOREP_VERSION}.tar.gz" tar -xf "scorep-${SCOREP_VERSION}.tar.gz" cd "scorep-${SCOREP_VERSION}" ./configure --with-mpi=openmpi --enable-shared --without-llvm --without-shmem --without-cubelib --prefix="/opt/scorep-${SCOREP_VERSION}" make -j $( nproc ) make install # Add /opt/scorep to your path variables on shell start cat <> ~/.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 echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid # Check whether it works scorep --version scorep-info config-summary ``` -------------------------------- ### Basic usage of rapidgzip Python library Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Provides a basic example of using the `RapidgzipFile` class from the rapidgzip Python library. It demonstrates opening a gzip file with parallelization, reading the entire content, seeking to a specific position, reading a chunk, and getting the current file position. ```python import os from rapidgzip import RapidgzipFile # Open gzip file with parallel decompression file = RapidgzipFile("example.gz", parallelization=os.cpu_count()) # Read entire file data = file.read() print(f"Decompressed size: {len(data)} bytes") # Seek and read specific portion file.seek(1000) chunk = file.read(500) print(f"Read {len(chunk)} bytes from offset 1000") # Get current position position = file.tell() print(f"Current position: {position}") # Close file file.close() ``` -------------------------------- ### Using rapidgzip with ratarmount for mounting gzip files Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Shows command-line examples of creating a large sample gzip file, mounting it using ratarmount, and performing serial and parallel decoding, as well as random seeking. ```bash base64 /dev/urandom | head -c $(( 4 * 1024 * 1024 * 1024 )) | gzip > sample.gz # Serial decoding: 23 s time gzip -c -d sample.gz | wc -c python3 -m pip install --user ratarmount ratarmount sample.gz mounted # Parallel decoding: 3.5 s time cat mounted/sample | wc -c # Random seeking to the middle of the file and reading 1 MiB: 0.287 s time dd if=mounted/sample bs=$(( 1024 * 1024 )) \ iflag=skip_bytes,count_bytes skip=$(( 2 * 1024 * 1024 * 1024 )) count=$(( 1024 * 1024 )) | wc -c ``` -------------------------------- ### Build and Install Rapidgzip Locally Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md Builds the Rapidgzip package locally from a cloned repository and installs it using pip. This process involves cloning the repository, navigating to the Python package directory, cleaning previous builds, using the 'build' tool, and then installing the generated wheel file. ```bash git clone --recursive https://github.com/mxmlnkn/rapidgzip.git cd rapidgzip/python/rapidgzip/ rm -rf dist python3 -m build python3 -m pip install --force-reinstall --user --break-system-packages dist/rapidgzip-*.whl ``` -------------------------------- ### Integrating rapidgzip C++ library with CMake FetchContent Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Provides a conceptual reference to integrating the header-only rapidgzip C++ library into a CMake project using the FetchContent module. A specific example can be found in the linked repository. ```cmake # Example CMakeLists.txt snippet using FetchContent # include(FetchContent) # FetchContent_Declare( # rapidgzip # GIT_REPOSITORY https://github.com/mxmlnkn/rapidgzip.git # GIT_TAG # ) # FetchContent_MakeAvailable(rapidgzip) # target_link_libraries(your_target PRIVATE rapidgzip::rapidgzip) ``` -------------------------------- ### Using Ratarmount with Rapidgzip Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Instructions for installing ratarmount and using it to mount gzip files as FUSE filesystems. This allows transparent access to decompressed content and demonstrates fast random access. ```bash # Install ratarmount (includes rapidgzip backend) python3 -m pip install --user ratarmount # Create a large gzip file for testing base64 /dev/urandom | head -c $(( 4 * 1024 * 1024 * 1024 )) | gzip > sample.gz # Mount gzip file as filesystem ratarmount sample.gz mounted/ # Access decompressed content transparently cat mounted/sample | wc -c # Random access is fast after index creation dd if=mounted/sample bs=1M iflag=skip_bytes,count_bytes \ skip=$((2*1024*1024*1024)) count=$((1024*1024)) | wc -c # Unmount when done fusermount -u mounted/ ``` -------------------------------- ### C++ Example Usage of Rapidgzip Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Demonstrates basic C++ usage of the rapidgzip library for reading decompressed data from a gzip file. It shows how to open a file with ParallelGzipReader, read data into a buffer, and perform seeks. ```cpp // main.cpp - Example C++ usage #include #include #include int main() { // Open gzip file with parallel reader auto reader = std::make_unique( std::make_unique("example.gz") ); // Read decompressed data std::vector buffer(4096); size_t bytesRead = reader->read(buffer.data(), buffer.size()); std::cout << "Read " << bytesRead << " bytes\n"; // Seek to position reader->seek(1000); bytesRead = reader->read(buffer.data(), buffer.size()); std::cout << "Read " << bytesRead << " bytes from offset 1000\n"; return 0; } ``` -------------------------------- ### Install Latest Development Version from GitHub Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md Installs the latest unreleased development version of Rapidgzip directly from its GitHub repository. This command clones the repository and installs the package, ensuring you have the most recent features and fixes. ```bash python3 -m pip install --force-reinstall 'git+https://github.com/mxmlnkn/rapidgzip.git@main#egginfo=rapidgzip&subdirectory=python/rapidgzip' ``` -------------------------------- ### Install Rapidgzip using pip Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md Installs the Rapidgzip Python package using pip. It's recommended to upgrade pip first for compatibility with newer manylinux wheels. After installation, you can verify it by running the help command. ```bash python3 -m pip install --upgrade pip python3 -m pip install rapidgzip rapidgzip --help ``` -------------------------------- ### Build Rapidgzip from Source (Debian/Ubuntu) Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md Installs necessary build dependencies for Rapidgzip on Debian-based systems, including git, C++ compiler, Python development headers, and build tools. This is a prerequisite for building from source. ```bash sudo apt install git gcc g++ python3 python3-dev python3-pip python3-build python3-venv nasm ``` -------------------------------- ### Basic gzip file operations in Python Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Demonstrates opening, seeking, reading, and closing a gzip file using RapidgzipFile. The first seek operation might be slower as it can trigger the creation of the block offset list. ```python from rapidgzip import RapidgzipFile import os file = RapidgzipFile("example.gz", parallelization=os.cpu_count()) # You can now use it like a normal file file.seek(123) data = file.read(100) file.close() ``` -------------------------------- ### Manage gzip index files with rapidgzip CLI Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Explains how to create, import, and export gzip index files using the rapidgzip command-line tool. It covers creating indexes for faster decompression, using existing indexes, exporting in different formats (gztool, gztool-with-lines), and converting between formats. ```bash # Decompress and create an index for future use rapidgzip -d -P 0 --export-index archive.gz.index archive.gz # Use existing index for faster decompression rapidgzip -d -P 0 --import-index archive.gz.index archive.gz # Export index in gztool format (compatible with gztool) rapidgzip -d --export-index archive.gzi --index-format gztool archive.gz # Export index with line offsets for line-based seeking rapidgzip -d --export-index archive.gzi --index-format gztool-with-lines archive.gz # Convert between index formats rapidgzip --import-index archive.gz.index --export-index archive.gzi --index-format gztool archive.gz ``` -------------------------------- ### Using gzip file operations with a context manager in Python Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Shows how to use rapidgzip.open with a context manager (`with` statement) for automatic file closing. This is a more Pythonic way to handle file operations. ```python import os import rapidgzip with rapidgzip.open("example.gz", parallelization=os.cpu_count()) as file: file.seek(123) data = file.read(100) ``` -------------------------------- ### Display rapidgzip help information Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md This command displays the help message for the rapidgzip command-line tool, outlining available options and usage instructions. It requires no specific input files. ```bash rapidgzip --help ``` -------------------------------- ### Python Advanced Options for Performance Tuning Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Explains how to configure advanced options for RapidgzipFile, such as chunk size for memory/speed tradeoffs and enabling verbose output for profiling. It also demonstrates the 'peek' method for non-consuming reads. ```python import os from rapidgzip import RapidgzipFile # Configure chunk size (in KiB) for parallel workers # Larger chunks = better throughput, higher memory usage file = RapidgzipFile( "example.gz", parallelization=os.cpu_count(), # chunk_size is configurable for memory/speed tradeoff ) # Enable verbose output for profiling file_verbose = RapidgzipFile( "example.gz", parallelization=os.cpu_count(), verbose=True # Prints timing and statistics ) # Read with peek (non-consuming read) with RapidgzipFile("example.gz", parallelization=os.cpu_count()) as f: # Peek at first 100 bytes without advancing position preview = f.peek(100) print(f"Preview: {preview[:50]}...") # Position unchanged print(f"Position after peek: {f.tell()}") # Now read advances position data = f.read(100) print(f"Position after read: {f.tell()}") file.close() file_verbose.close() ``` -------------------------------- ### Rapidgzip Performance Tuning Options Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Demonstrates various command-line options for tuning rapidgzip performance. This includes selecting I/O read methods, adjusting chunk size, and enabling/disabling CRC32 verification. ```bash # Use sequential I/O for slow storage (HDDs) rapidgzip -d -P 0 --io-read-method sequential archive.gz # Use pread for fast storage (SSDs, NVMe) - default rapidgzip -d -P 0 --io-read-method pread archive.gz # Adjust chunk size for memory-constrained systems (default 4096 KiB) rapidgzip -d -P 0 --chunk-size 1024 archive.gz # Enable CRC32 verification (adds ~5% overhead) rapidgzip -d -P 0 --verify archive.gz # Disable verification for maximum speed rapidgzip -d -P 0 --no-verify archive.gz # Verbose output for profiling and debugging rapidgzip -d -P 0 -v archive.gz 2>&1 | tail -20 ``` -------------------------------- ### Opening gzip files from in-memory bytes in Python Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Demonstrates how to use rapidgzip to read from an in-memory byte stream (io.BytesIO) instead of a file path. This is useful when the gzip data is already loaded into memory. ```python import io import os import rapidgzip as rapidgzip with open("example.gz", "rb") as file: in_memory_file = io.BytesIO(file.read()) with rapidgzip.open(in_memory_file, parallelization=os.cpu_count()) as file: file.seek(123) data = file.read(100) ``` -------------------------------- ### Storing and loading gzip index for faster access in Python Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md Explains how to export and import the block offset index to avoid re-calculating it on every file open. This significantly speeds up subsequent accesses to the same gzip file. ```python import os import rapidgzip index_path = "example.gz.gzindex" with rapidgzip.open("example.gz", parallelization=os.cpu_count()) as file: file.seek(123) data = file.read(100) file.export_index(index_path) with rapidgzip.open("example.gz", parallelization=os.cpu_count()) as file: file.import_index(index_path) file.seek(123) data = file.read(100) ``` -------------------------------- ### Basic parallel decompression with rapidgzip CLI Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Demonstrates basic parallel decompression using the rapidgzip command-line interface. It covers decompression to stdout, direct to file, with explicit thread control, overwriting existing files, and using stdin/stdout pipes. ```bash # Basic parallel decompression to stdout (uses all available cores) rapidgzip -d -c -P 0 archive.gz > output.txt # Decompress to file (removes .gz extension automatically) rapidgzip -d archive.gz # Decompress with explicit parallelism (12 threads) rapidgzip -d -P 12 archive.gz # Force overwrite existing output file rapidgzip -d -f -o output.txt archive.gz # Decompress from stdin to stdout cat archive.gz | rapidgzip -d -c > output.txt # Quiet mode (suppress non-critical messages) rapidgzip -d -q archive.gz ``` -------------------------------- ### Python Context Manager for Automatic Resource Cleanup Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Demonstrates using the context manager interface with rapidgzip.open() for automatic file closing. It shows how to seek to a specific position and read data from a gzip file, ensuring the file is properly closed upon exiting the 'with' block. ```python import os import rapidgzip # Context manager automatically closes file with rapidgzip.open("example.gz", parallelization=os.cpu_count()) as file: # Seek to specific position file.seek(123) # Read 100 bytes data = file.read(100) print(f"Read {len(data)} bytes") # Read remaining data remaining = file.read() print(f"Remaining: {len(remaining)} bytes") # File is automatically closed here ``` -------------------------------- ### C++: Integrating Rapidgzip with CMake FetchContent Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md Illustrates how to add Rapidgzip as a header-only library to a CMake project using the `FetchContent` module. This allows for easy integration into C++ projects. ```cmake # Example CMakeLists.txt snippet using FetchContent include(FetchContent) FetchContent_Declare( rapidgzip GIT_REPOSITORY https://github.com/mxmlnkn/rapidgzip.git GIT_TAG main # Or a specific release tag ) FetchContent_MakeAvailable(rapidgzip) target_link_libraries(your_target PRIVATE rapidgzip::rapidgzip) ``` -------------------------------- ### Analyze gzip file structure with rapidgzip CLI Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Shows how to inspect the internal structure of gzip files using the `--analyze` option in the rapidgzip command-line tool. This provides details about deflate blocks, streams, compression statistics, and code length histograms. ```bash # Analyze gzip file structure rapidgzip --analyze archive.gz ``` -------------------------------- ### CMake Integration for Rapidgzip Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Integrates the rapidgzip library into a CMake project using FetchContent. It declares the repository, fetches the content, and links the executable against the rapidgzip library. ```cmake cmake_minimum_required(VERSION 3.14) project(myproject) include(FetchContent) FetchContent_Declare( rapidgzip GIT_REPOSITORY https://github.com/mxmlnkn/indexed_bzip2.git GIT_TAG master ) FetchContent_MakeAvailable(rapidgzip) add_executable(myapp main.cpp) target_link_libraries(myapp PRIVATE rapidgzip::rapidgzip) ``` -------------------------------- ### Python File Type Detection for Compression Formats Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Demonstrates how to use RapidgzipFile to automatically detect the compression format of input files. It shows how to access the 'file_type' attribute to identify gzip, bgzf, zlib, or deflate formats. ```python from rapidgzip import RapidgzipFile # Open file and check detected type with RapidgzipFile("example.gz") as f: file_type = f.file_type print(f"Detected file type: {file_type}") # Possible values: GZIP, BGZF, ZLIB, DEFLATE, None # Works with different compression formats # GZIP - Standard gzip format (.gz files) # BGZF - Blocked gzip format (used by bioinformatics tools) # ZLIB - Zlib-wrapped deflate # DEFLATE - Raw deflate stream ``` -------------------------------- ### C++ CMake Integration for Header-Only Usage Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Provides a CMake configuration snippet for integrating the rapidgzip C++ library into a project. It utilizes CMake FetchContent to include the library as header-only, simplifying dependency management. ```cmake include(FetchContent) FetchContent_Declare( rapidgzip GIT_REPOSITORY https://github.com/mxmlnkn/rapidgzip.git GIT_TAG main # Or a specific release tag ) FetchContent_MakeAvailable(rapidgzip) add_executable(my_app main.cpp) target_link_libraries(my_app PRIVATE rapidgzip::rapidgzip) ``` -------------------------------- ### Count decompressed size and lines with rapidgzip CLI Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Demonstrates how to quickly obtain statistics like the decompressed size and line count of a gzip file without full decompression, especially when an index is available. It also shows how to use these commands in scripts. ```bash # Count decompressed bytes (fast with index) rapidgzip --count archive.gz # Count newlines in decompressed data rapidgzip --count-lines archive.gz # Fast line counting with existing index rapidgzip --import-index archive.gz.index --count-lines archive.gz # Combined with quiet mode for scripting SIZE=$(rapidgzip -q --count archive.gz) LINES=$(rapidgzip -q --count-lines archive.gz) ``` -------------------------------- ### Python In-Memory and File-Like Object Handling Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Shows how to use rapidgzip with in-memory byte buffers (io.BytesIO) and custom file-like objects. This allows for parallel decompression of data that is not stored in a physical file, offering flexibility in data handling. ```python import io import os import rapidgzip # Load gzip data into memory with open("example.gz", "rb") as f: gzip_data = f.read() # Create in-memory file object in_memory_file = io.BytesIO(gzip_data) # Use rapidgzip with the in-memory file with rapidgzip.open(in_memory_file, parallelization=os.cpu_count()) as file: file.seek(123) data = file.read(100) print(f"Read {len(data)} bytes from in-memory buffer") # Also works with any file-like object class CustomFileObject: def __init__(self, data): self.data = data self.pos = 0 def read(self, size=-1): if size < 0: result = self.data[self.pos:] self.pos = len(self.data) else: result = self.data[self.pos:self.pos + size] self.pos += len(result) return result def seek(self, pos, whence=0): if whence == 0: self.pos = pos elif whence == 1: self.pos += pos elif whence == 2: self.pos = len(self.data) + pos return self.pos def tell(self): return self.pos custom_file = CustomFileObject(gzip_data) with rapidgzip.open(custom_file, parallelization=os.cpu_count()) as file: data = file.read() print(f"Decompressed {len(data)} bytes from custom file object") ``` -------------------------------- ### Python Index Management for Faster Gzip Access Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Illustrates exporting and importing index files to speed up repeated access to gzip files. The first access creates and exports the index, while subsequent accesses import the index for significantly faster seeking operations. ```python import os import rapidgzip index_path = "example.gz.gzindex" # First access: decompress and create index with rapidgzip.open("example.gz", parallelization=os.cpu_count()) as file: # Trigger full index creation by seeking file.seek(0, 2) # Seek to end file.seek(0) # Seek back to start # Export index for future use file.export_index(index_path) print(f"Index exported to {index_path}") # Subsequent access: use existing index (much faster) with rapidgzip.open("example.gz", parallelization=os.cpu_count()) as file: # Import index before seeking file.import_index(index_path) # Now seeking is fast file.seek(1000000) data = file.read(100) print(f"Read {len(data)} bytes at offset 1M") ``` -------------------------------- ### Parallel decompression with rapidgzip Source: https://github.com/mxmlnkn/rapidgzip/blob/main/README.md This command demonstrates parallel decompression of a sample file using rapidgzip. It measures the time taken and pipes the decompressed output to `wc -c` to count the characters. The `-P 0` flag enables full parallel decompression. ```bash time rapidgzip -d -c -P 0 sample.gz | wc -c ``` -------------------------------- ### Decompress byte and line ranges with rapidgzip CLI Source: https://context7.com/mxmlnkn/rapidgzip/llms.txt Illustrates how to extract specific portions of decompressed data using byte or line offsets with the `--ranges` option in rapidgzip. It covers decompressing byte ranges, line ranges, multiple ranges, and reading from an offset to the end of the file. ```bash # Decompress first 1000 bytes rapidgzip -d -c --ranges 1000@0 archive.gz # Decompress 1 KiB starting at offset 15 KiB rapidgzip -d -c --ranges 1KiB@15KiB archive.gz # Decompress 5 lines starting after line 20 rapidgzip -d -c --ranges 5L@20L archive.gz # Multiple ranges in one command rapidgzip -d -c --ranges "10@0,1KiB@15KiB,5L@20L" archive.gz # Read from offset to end of file rapidgzip -d -c --ranges inf@1MiB archive.gz ``` -------------------------------- ### BibTeX Citation for Rapidgzip Source: https://github.com/mxmlnkn/rapidgzip/blob/main/python/rapidgzip/README.md This BibTeX entry provides the necessary details to cite the Rapidgzip paper in academic publications. It includes author information, title, publication venue, and abstract. ```bibtex @inproceedings{rapidgzip, author = {Knespel, Maximilian and Brunst, Holger}, title = {Rapidgzip: Parallel Decompression and Seeking in Gzip Files Using Cache Prefetching}, year = {2023}, isbn = {9798400701559}, publisher = {Association for Computing Machinery}, address = {New York, NY, USA}, url = {https://doi.org/10.1145/3588195.3592992}, doi = {10.1145/3588195.3592992}, abstract = {Gzip is a file compression format, which is ubiquitously used. Although a multitude of gzip implementations exist, only pugz can fully utilize current multi-core processor architectures for decompression. Yet, pugz cannot decompress arbitrary gzip files. It requires the decompressed stream to only contain byte values 9–126. In this work, we present a generalization of the parallelization scheme used by pugz that can be reliably applied to arbitrary gzip-compressed data without compromising performance. We show that the requirements on the file contents posed by pugz can be dropped by implementing an architecture based on a cache and a parallelized prefetcher. This architecture can safely handle faulty decompression results, which can appear when threads start decompressing in the middle of a gzip file by using trial and error. Using 128 cores, our implementation reaches 8.7 GB/s decompression bandwidth for gzip-compressed base64-encoded data, a speedup of 55 over the single-threaded GNU gzip, and 5.6 GB/s for the Silesia corpus, a speedup of 33 over GNU gzip.}, booktitle = {Proceedings of the 32nd International Symposium on High-Performance Parallel and Distributed Computing}, pages = {295–307}, numpages = {13}, keywords = {gzip, decompression, parallel algorithm, performance, random access}, location = {Orlando, FL, USA}, series = {HPDC '23}, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.