Client-side spatiotemporal vectorization for lossless data deduplication. Achieve 80-95% storage reduction with zero dependencies.
npm install ists-protocolbash
npm install ists-protocol
`
Or use via CDN:
`html
`
Quick Start
$3
`javascript
import ISTS from 'ists-protocol';
const ists = new ISTS();
// Compress text
const result = ists.compressText("Your large text data here...");
console.log(Saved ${result.savingsPercent}%);
// Output: Saved 91.2%
// Decompress
const original = ists.decompressText(result.compressed);
`
$3
`javascript
const ists = new ISTS();
// Compress image file
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const result = await ists.compressImage(file);
console.log(Original: ${ISTS.formatBytes(result.originalSize)});
console.log(Compressed: ${ISTS.formatBytes(result.compressedSize)});
console.log(Savings: ${result.savingsPercent}%);
// Restore image
const dataURL = ists.decompressImage(result.compressed, result.mime);
document.querySelector('img').src = dataURL;
`
$3
`javascript
const ists = new ISTS();
// Load existing ledger
await ists.loadLedger();
// Compress and save
const compressed = ists.compressText("Data to store");
await ists.storage.set('myData', compressed.compressed);
// Save ledger for future sessions
await ists.saveLedger();
// Later: retrieve and decompress
const stored = await ists.storage.get('myData');
const original = ists.decompressText(stored);
`
How It Works
$3
ISTS uses a dictionary-based vectorization approach:
1. Tokenization: Text is split into tokens (words, numbers, symbols)
2. Ledger Mapping: Each unique token is assigned a numeric ID in a global ledger
3. Vectorization: Text is converted to a sequence of numeric coefficients
4. Compression: Coefficients are compressed using LZ-String UTF-16 encoding
Example:
`
Input: "hello world hello"
Tokens: ["hello", " ", "world", " ", "hello"]
Ledger: {"hello": 0, " ": 1, "world": 2}
Vector: [0, 1, 2, 1, 0]
Result: Compressed coefficient string
`
$3
For images, ISTS employs a canvas-based WebP encoding strategy:
1. Canvas Rendering: Image is drawn to HTML5 Canvas
2. WebP Encoding: Canvas exports to WebP format at 85% quality (perceptually lossless)
3. Base64 Conversion: Binary data converted to Base64 string
4. LZ Compression: Base64 string compressed with LZ-String
This achieves 80-90% reduction compared to raw PNG/JPEG storage.
Benchmarks
Performance comparison on various data types:
| Data Type | Original Size | ISTS Compressed | Savings | Method |
|-----------|--------------|-----------------|---------|--------|
| Repetitive Text | 1.2 MB | 108 KB | 91% | Global Ledger |
| JSON Data | 850 KB | 127 KB | 85% | Global Ledger |
| PNG Image | 2.4 MB | 312 KB | 87% | Canvas WebP |
| JPEG Image | 1.8 MB | 298 KB | 83% | Canvas WebP |
| Mixed Content | 5.0 MB | 620 KB | 88% | Hybrid |
vs. LocalStorage Raw: 10x improvement
vs. IndexedDB Raw: 8x improvement
vs. gzip: 2-3x better on repetitive data
API Reference
$3
`javascript
const ists = new ISTS(options);
`
Options:
- dbName (string): IndexedDB database name (default: 'ISTS_Storage')
- storeName (string): Object store name (default: 'keyval')
- ledgerKey (string): Ledger storage key (default: 'ISTS_GLOBAL_LEDGER')
$3
#### compressText(text)
Compress text data using global ledger.
Returns:
`javascript
{
compressed: string, // Compressed data
originalSize: number, // Original byte size
compressedSize: number, // Compressed byte size
savingsPercent: number, // Compression ratio %
tokenCount: number // Number of tokens
}
`
#### decompressText(compressed)
Decompress text data.
Returns: string - Original text
$3
#### compressImage(file, options)
Compress image file.
Parameters:
- file (File|Blob): Image file
- options (Object):
- quality (number): WebP quality 0-1 (default: 0.85)
- maxDimension (number): Max width/height (default: 3840)
- format (string): Output format (default: 'image/webp')
Returns: Promise