Skip to main content

A Python library for handling Microsoft Cabinet files with zipfile-like interface

Project description

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

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

pycabfile-1.0.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycabfile-1.0.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file pycabfile-1.0.0.tar.gz.

File metadata

  • Download URL: pycabfile-1.0.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for pycabfile-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f931dd148987eb4bbdac2b1dfa3d74cdaa4d1ae5e1c82cdb0b55e30b32877b9a
MD5 cd4ec1632eda1a36a80589f103a8fe51
BLAKE2b-256 e96d1daec9cfb01d1cb4407c9a883c843dee4dccdf622642ce37cd6b3e14eedc

See more details on using hashes here.

File details

Details for the file pycabfile-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycabfile-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for pycabfile-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa362fe23741f4166907197065258b3030986ae2baf93b817c30fe1ff3f3ff88
MD5 696ec05d4a5b29ebd6dc35c31e8a1717
BLAKE2b-256 a6a3f6fe18b517d011dffd591794f4e9dbe0e78353e948b9e454871b7d34ef29

See more details on using hashes here.

Supported by

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