pycabfile
A Python library for handling Microsoft Cabinet files with zipfile-compatible interface
Python 3.10+ Compatible - This library provides a zipfile-like interface for creating and extracting CAB files, fully compatible with Python 3.10 and later versions.
Features
- zipfile-compatible interface - Use the same methods as Python's zipfile module
- Create and extract CAB files with simple API
- Support for binary and text files
- Unicode filename support
- Context manager support (with statement)
- No external dependencies required
- Python 3.10+ support - Fully compatible with modern Python versions
Installation
pip install pycabfile
# or Install from source
pip install git+https://github.com/hanul93/pycabfile.git
Quick Start
The interface is designed to be identical to Python's zipfile module:
Creating CAB Files
from pycabfile import CabFile
# Create a new CAB file
with CabFile('example.cab', 'w') as cab:
# Add files from disk
cab.write('document.txt', 'docs/document.txt') # arcname is optional
cab.write('image.jpg')
# Add data directly
cab.writestr('readme.txt', 'This is a README file')
cab.writestr('config.json', '{"version": "1.0"}')
Reading CAB Files
from pycabfile import CabFile
# Read an existing CAB file
with CabFile('example.cab', 'r') as cab:
# List all files
file_list = cab.namelist()
print(f"Files in CAB: {file_list}")
# Read file content
content = cab.read('readme.txt')
print(content.decode('utf-8'))
# Get file information
info = cab.getinfo('document.txt')
print(f"File size: {info.file_size} bytes")
# Extract files
cab.extract('document.txt', 'output/') # Extract single file
cab.extractall('output/') # Extract all files
Advanced Usage
from pycabfile import CabFile, CabInfo
# Append to existing CAB file
with CabFile('example.cab', 'a') as cab:
cab.writestr('appended.txt', 'This was added later')
# Working with file-like objects
with CabFile('example.cab', 'r') as cab:
with cab.open('document.txt') as f:
data = f.read()
print(data.decode('utf-8'))
Comparison with zipfile
The API is designed to be a drop-in replacement for zipfile in most cases:
| zipfile | pycabfile |
|---|---|
zipfile.ZipFile('file.zip', 'w') |
CabFile('file.cab', 'w') |
zf.write('file.txt') |
cf.write('file.txt') |
zf.writestr('name', data) |
cf.writestr('name', data) |
zf.read('name') |
cf.read('name') |
zf.namelist() |
cf.namelist() |
zf.extractall() |
cf.extractall() |
Testing
Run the test suite:
# Basic functionality test
python test_pycabfile.py
# Run example demo
python example.py
Requirements
- Python 3.10+
- No external dependencies required
Authors
- Kei Choi (developer)
License
MIT License
Technical Details
This library provides a pure Python implementation for handling Microsoft Cabinet files with a zipfile-compatible interface. It implements the CAB format specification from Microsoft to ensure full compatibility with standard CAB files created by other tools.
CAB Format Information
For more information about the Microsoft Cabinet format: https://msdn.microsoft.com/en-us/library/bb417343.aspx
Metadata
Release files for pycabfile 1.0.0
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 |
|---|---|---|---|---|
| pycabfile-1.0.0.tar.gz | 18.6 kB | Without provenance | Details for pycabfile-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycabfile-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for pycabfile-1.0.0-py3-none-any.whl |
Total release size: 39.4 kB
Release files / pycabfile-1.0.0.tar.gz
| Download URL | pycabfile-1.0.0.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f931dd148987eb4bbdac2b1dfa3d74cdaa4d1ae5e1c82cdb0b55e30b32877b9a
|
|
BLAKE2b-256 checksum How to use checksums |
e96d1daec9cfb01d1cb4407c9a883c843dee4dccdf622642ce37cd6b3e14eedc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|
Release files / pycabfile-1.0.0-py3-none-any.whl
| Download URL | pycabfile-1.0.0-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa362fe23741f4166907197065258b3030986ae2baf93b817c30fe1ff3f3ff88
|
|
BLAKE2b-256 checksum How to use checksums |
a6a3f6fe18b517d011dffd591794f4e9dbe0e78353e948b9e454871b7d34ef29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|
Security for pycabfile 1.0.0
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.