Compressed RTF

1.0.7 · active · verified Fri Apr 10

Compressed Rich Text Format (RTF) compression and decompression package. It supports the LZFu compression format, based on the Microsoft RTF Compression Algorithm. The current version is 1.0.7, and releases are infrequent, primarily for bug fixes.

Warnings

Install

Imports

Quickstart

Demonstrates how to compress and decompress RTF byte data using the `compress` and `decompress` functions.

from compressed_rtf import compress, decompress

# Example RTF data (must be bytes)
rtf_data = b'{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}{\f1\fnil\fcharset2 Symbol;}}
{\pard\sa200\sl276\slmult1\f0\fs22\lang9 This is some \b compressed\b0  RTF data.\par}
}
'

# Compress the data
compressed_bytes = compress(rtf_data)
print(f"Original size: {len(rtf_data)} bytes")
print(f"Compressed size: {len(compressed_bytes)} bytes")

# Decompress the data
decompressed_bytes = decompress(compressed_bytes)

# Verify decompression
assert decompressed_bytes == rtf_data
print("Decompression successful!")
print(f"Decompressed content: {decompressed_bytes.decode('ascii', errors='ignore')[:50]}...")

view raw JSON →