Skip to main content

pymszip

This library fills the very niche use-case where you have data compressed using CreateCompressor / Compress with the MSZIP algorithm, and want to decompress it without the Windows API (e.g. under Linux), or the other way around and you want to create compressed data that can be decompressed by the Windows API.

Installation

pip install pymszip

Alternatively, install directly from GitHub:

pip install git+https://github.com/frereit/pymszip

Usage

import pymszip

compressed = pymszip.compress(b"Hello, world!")
decompressed = pymszip.decompress(compressed)

print(decompressed)

Goals and non-goals

This repo aims to provide full compatibility with the Windows API. This means that:

  • Any data compressed using the Windows API can be decompressed by pymszip
  • Any data compressed using pymszip can be decompressed by the Windows API

If you find data where either of this isn't the case, please file an issue if you can!

However, this library does not aim to produce identical results to the Windows compression. This means data compressed using pymszip may yield different results than if it was compressed with the Windows API. This is to be expected because of slightly differing zlib parameters, but not an issue, as long as compatibility is preserved.

MSZIP format

The MSZIP compression format is a proprietary compression format developed by Microsoft, based on the zlib compression library.

Under the hood, MSZIP compressed data is prefixed with a 24 byte header, and an arbitrary number of compressed chunks following it.

The header consiss of 6 magic bytes (0a51e5c01800)[^magic], followed by 1 CRC byte, 1 byte to identify the algorithm (MSZIP / 02), followed by 8 bytes little-endian integer to specify the decompressed size of the data, and another 8 bytes little-endian integer to specify the decompressed size of the first chunk.

Each chunk is prefixed with a 4 byte little-endian integer to specify its size, and 2 magic bytes ("CK"), after which a zlib-compressed stream follows. The "size" of the chunk includes the zlib stream, and the 2 magic bytes, but not the size header itself.

To decompress data, each zlib-compressed stream is decompressed individually, however each chunk must be given all previously decompressed data as the zdict used during decompression.

To compress data, a similar process is followed. Experimentially, I came to the conclusion that the memLevel must be set to 9`, or Windows will not be able to decompress the compressed data again in some cases.

Metadata

Release files for pymszip 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymszip 1.0.1
File Size Uploaded
pymszip-1.0.1.tar.gz 3.9 kB Details

Built distribution (wheel)

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

Total release size: 8.1 kB

Release files / pymszip-1.0.1.tar.gz

Download URL pymszip-1.0.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c4b8ea7047933f08f05ce7aba3eddcf1a453bb570e40092390250a8e258f65e2
BLAKE2b-256 checksum
How to use checksums
1a5a9bdb96479c587d9e42f970f456f72162e314d64398acee7499214f88ef8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.1

Release files / pymszip-1.0.1-py3-none-any.whl

Download URL pymszip-1.0.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
843e807e6caa95690fadda8c426ce9c48c71313f6c3ee27dc303ff139579a54f
BLAKE2b-256 checksum
How to use checksums
ec503db29f37126648c8e3c9a065148c4fc5eb698611c825d3190d48c600d30a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.1

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

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