Skip to main content

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

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

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)

Source distribution for pycabfile 1.0.0
File Size Uploaded
pycabfile-1.0.0.tar.gz 18.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycabfile 1.0.0
File Interpreter ABI Platform
pycabfile-1.0.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page