string_compression¶
shortfx.fxString.string_compression
¶
String Compression and Decompression Functions.
This module provides functions for compressing and decompressing strings using zlib, returning Base64-encoded representations for safe transport.
Key Features: - zlib-based text compression with Base64 output - Decompression from Base64-encoded compressed data
Functions¶
compress_string(text: str, encoding: str = 'utf-8') -> str
¶
Compresses a string using zlib and returns a Base64-encoded result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to compress. |
required |
encoding
|
str
|
Character encoding to use before compression. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
A Base64-encoded string of the compressed data. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
compressed = compress_string("hello " * 100) len(compressed) < len("hello " * 100) True
Complexity: O(n)
Source code in shortfx/fxString/string_compression.py
decompress_string(compressed_text: str, encoding: str = 'utf-8') -> str
¶
Decompresses a Base64-encoded zlib-compressed string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compressed_text
|
str
|
The Base64-encoded compressed string. |
required |
encoding
|
str
|
Character encoding to use after decompression. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
The original decompressed text. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If compressed_text is not a string. |
ValueError
|
If the input is not valid compressed data. |
Example
decompress_string(compress_string("hello world")) 'hello world'
Complexity: O(n)