Shrink은 최소한의 노력으로 빠르게 데이터를 압축할 수 있도록 설계된 가벼운 Flutter/Dart 패키지입니다. 단일 함수를 호출함으로써 개발자는 데이터 크기를 5배에서 40배까지 줄일 수 있으며, Firebase 스토리지, JSON 페이로드 및 구조화된 데이터 최적화에 이상적입니다. 성능과 간편함을 고려하여 제작된 Shrink는 Android, iOS, Web, macOS, Windows, Linux 등 주요 플랫폼 전반에 걸쳐 원활하게 통합됩니다. 대량의 직렬화 가능한 데이터를 처리하고 효율적인 저장 또는 전송이 필요한 애플리케이션에 특히 유용합니다.
사용 사례
Firebase용 JSON 데이터 압축
앱 페이로드 크기 줄이기
구조화된 데이터 저장 최적화
네트워크 전송 비용 최소화
로컬 데이터 효율성 향상
데이터 동기화 프로세스 간소화
주요 기능
단일 줄 압축 API
5x–40x 크기 축소
Firebase-optimized
크로스 플랫폼 지원
가볍고 빠름
구조화된 데이터를 지원합니다
적합한 대상
Firebase 사용 앱
데이터 중심 모바일 앱
네트워크 효율적인 앱
JSON 기반 API
빠른 압축을 원하는 개발자
저저장 환경
고려 사항
이진 데이터에 적합하지 않을 수 있습니다
작은 데이터 세트에서의 압축 오버헤드
제한된 사용자 지정 옵션
암호화를 위한 것이 아님
크기와 속도 사이의 신중한 트레이드오프가 필요합니다
원시 미디어가 아닌 텍스트/구조화된 데이터에 최적
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Because every byte counts.
Compress any data in one line — no setup, no boilerplate, and nothing to configure. It automatically detects if compression is beneficial, chooses the most efficient method, and keeps everything fully lossless. Typical savings range from 5× to 40×, and can reach 1,000× or more with structured data. Ideal for reducing size in Firebase, speeding up local storage, and optimizing for low-bandwidth environments.
Compression is as easy as calling .shrink() on your data — no setup, no boilerplate.
final compressed = data.shrink(); // ⬇️ Compress your data
Or use the static Shrink class for clarity:
final compressed = Shrink.json(data);
Works with: String, Map<String, dynamic>, Uint8List, and List<int> (unique IDs)
🔓 Restore Instantly
To get your original data back, just call .restoreX() on the compressed value:
final restored = compressed.restoreJson(); // ⬆️ Restore original content
Or use the static Restore class:
final restored = Restore.json(compressed);
Every shrink operation is lossless — the restored value is identical to the original.
What Can I Shrink?!
Real-world data — from network packets to text content — is rarely random. It contains patterns and structure that enable efficient compression. In typical use, shrink reduces data size by 5× to 10×. With highly structured data, compression can reach 100× or even 1,000× smaller. For example, a 1MB list of sequential IDs can shrink to just a few bytes.
🔢 List<int> (Unique Integers)
Perfect for ID lists like inventory items, selected flags, indexes, or any sparse/sequential keys. Optimized for sets of non-repeating integers.
🧠 Uint8List (Raw Bytes)
Great for custom compression workflows — convert anything to bytes and shrink it efficiently. Ideal for binary data or serialized formats.
✍️ String (Text)
Compress plain text directly and restore it back as a String. Works well for logs, messages, descriptions, or long content fields.
📦 Map<String, dynamic> (JSON)
Shrinks any Map<String, dynamic> by compressing the serialized string. Especially useful for structured or repetitive data — great for Firebase, config files, and API payloads.
Shrink any supported data using the extension or static API.
Don’t shrink twice — it just adds a byte.
Use the correct restore method for the data type.
✅ Extension API (.shrink() → .restoreX())
Data Type
Shrink
Restore
Unique Integers
items.shrink()
shrinked.restoreUnique()
Text (String)
text.shrink()
shrinked.restoreText()
JSON (Map)
data.shrink()
shrinked.restoreJson()
Bytes (Uint8List)
bytes.shrink()
shrinked.restoreBytes()
🧱 Static API (Shrink.x() → Restore.x())
Data Type
Shrink
Restore
Unique Integers
Shrink.unique(items)
Restore.unique(shrinked)
Text (String)
Shrink.text(text)
Restore.text(shrinked)
JSON (Map)
Shrink.json(data)
Restore.json(shrinked)
Bytes (Uint8List)
Shrink.bytes(bytes)
Restore.bytes(shrinked)
⬇️ Shrinking in code
final shrinkedItems = items.shrink();
final shrinkedText = text.shrink();
final shrinkedJson = data.shrink();
final shrinkedBytes = data.shrink()
Or use the static Shrink class for a clean, explicit API:
final shrinkedItems = Shrink.unique(items);
final shrinkedText = Shrink.text(text);
final shrinkedJson = Shrink.json(data);
final shrinkedBytes = Shrink.bytes(bytes);
🔓 Restoring in code
Easily restore compressed data using .restoreX():
final restoredItems = shrinkedItems.restoreUnique();
final restoredText = shrinkedText.restoreText();
final restoredJson = shrinkedJson.restoreJson();
final restoredBytes = shrinkedBytes.restoreBytes();
Or with the static Restore class:
final restoredItems = Restore.unique(shrinkedItems);
final restoredText = Restore.text(shrinkedText);
final restoredJson = Restore.json(shrinkedJson);
final restoredBytes = Restore.bytes(shrinkedBytes);
📊 Benchmarks
🛡 Built for the long haul.
When shrink gets faster, smaller, and smarter — you don’t have to lift a finger.
Every version in the 1.x.x line is fully backward compatible.
Your existing data will always decompress perfectly, no matter how the internals evolve.
Just update and enjoy the gains — no migrations, no breakage, no surprises.
shrink has been benchmarked with a variety of real-world data scenarios, including:
Raw bytes: random, repetitive, alternating, zero-filled
JSON: flat, nested, arrays, and complex structures
Lists of unique integers: sequential, sparse, dense, and special patterns
Compression results vary depending on the input but can reach up to 200,000× reduction in size. All tests are validated and performance-logged.
🧩 Bytes & Text Shrinking
In almost every real-world scenario — from network packets and sensor logs to text content and protocol buffers — data is not truly random. Even when it appears non-repetitive at a low level, real data almost always contains some form of structure, patterns, or repetition:
Character frequency in text (e.g., spaces, vowels, tags)
Binary signatures in files and headers
Zero-padded or default values in structured formats
Protocol overhead in serialized data
That’s why compression can be so effective even on data that doesn’t look obviously redundant.
Shrink leverages this reality and combines compression strategies to achieve significant reductions for most data types.
📦 Compression Results (Bytes & Text)
Data Pattern
Input Size (Bytes)
Shrink Size
Space Saved
Factor
Random (1KB)
1,000
1,001
None
No gain
Repetitive (1KB)
1,000
27
97.3%
37.0×
Alternating Bytes
1,000
18
98.2%
55.6×
Mostly Zeros
1,000
73
92.7%
13.7×
🔍 Notes:
Large Alternating: Simulates binary signal streams or periodic sensor toggles (0x00, 0xFF, repeated).
Large Structured (Logs): Mimics repetitive log lines like INFO [12:00] Started....
Large Repeated Strings: Represents large user content with repeated headers, phrases, or template fragments.
💡 In Shrink, when compression doesn’t help, it’s intelligently skipped — so there’s no overhead.
📄 JSON Shrinking
Type
Original Size
Shrink Size
Space Saved
Factor
Simple Flat
51
52
None
No gain
Deeply Nested & Small
85
62
27.06%
1.37×
Large Array
10,901
2,033
81.35%
5.36×
Repeated Struct.
10,591
623
94.12%
17.0×
Mixed Content
1,632
403
75.31%
4.05×
Large (12101 chars)
12,101
428
96.46%
28.27×
Real-world JSON (40K)
83,389
24,312
70.84%
3.43×
🔢 Unique Integer Lists
Pattern
Original Size
Shrink Size
Space Saved
Factor
Sequential (1k)
4,000
4
99.90%
1000×
Sparse-Low (1k)
4,000
630
84.25%
6.35×
Sparse-High (1k)
4,000
1,083
72.92%
3.69×
Chunked-Small (1k)
4,000
360
91.00%
11.11×
Chunked-Large (1k)
4,000
44
98.90%
90.91×
Huge Sequential (50k)
200,000
5
100.00%
40,000×
Mega-Sequential (250k)
1,000,000
5
100.00%
200,000×
🧠 Auto-Selected Compression Examples
Shrink automatically selects the best compression strategy based on your data:
Data Type
Original Size
Shrink Size
Space Saved
Factor
Mixed IDs
4,800
14
99.71%
343×
Multi-Modal
6,000
1045
82.58%
5.74×
Simulated IDs
12,000
3199
73.34%
3.75×
🔬 How It Works Under the Hood
The shrink package is designed for production environments where data savings, ease of use, and data integrity matter most. Under the hood, each supported data type is compressed using a specialized and optimized algorithm, and decompressed using metadata-aware logic. All compression is lossless.
📦 Uint8List (Raw Bytes)
When using Shrink.bytes(...), the input is evaluated with multiple algorithms:
Identity (no compression)
Useful when compression would increase the data size.
ZLIB (optimized level between 4–9)
Fast, compact, and widely supported — ideal for structured or repetitive data.
The smallest result is selected automatically.
The first byte of the compressed output encodes the method used, so Restore.bytes(...) can safely reverse the process.
📝 String (Text)
Strings are first encoded as UTF-8, then compressed using Bytes Shrinking.
This strikes a balance between compression ratio and decoding speed, ideal for text-heavy content.
final compressed = 'hello world'.shrink();
final original = compressed.restoreText();
🔧 Map<String, dynamic> (JSON)
JSON is compressed in two steps:
Minify the data with jsonEncode (removes unnecessary whitespace).
Compress the resulting string with UTF-8 + Bytes Shrinking.
This results in excellent size reductions, especially for structured but repetitive data.
final compressed = {'name': 'John', 'age': 30}.shrink();
final restored = compressed.restoreJson();
🔢 List<int> (Unique Integers)
For lists of unique integers, shrink tries four specialized methods:
Delta + Varint Encoding
Great for sorted lists with small gaps.
Run-Length Encoding
Best when values appear in long consecutive runs.
Chunk-Based Encoding
Suitable for values that form localized clusters.
Bitmask Encoding
Excellent for dense ranges (e.g., 0–1000 with few missing values).
The algorithm selects the most space-efficient method and stores its index in the first byte.
You can also manually choose the method using .shrinkManual(...), though this is NOT RECOMMENDED since the automatic selection ensures optimal data compression by testing all methods.
final compressed = [1, 2, 3, 5, 6].shrink();
final restored = compressed.restoreUnique();
✅ Testing & Validation
All compression and restoration tools in shrink are:
Heavily tested for correctness, reversibility, and edge cases.
Guaranteed to preserve exact original content upon decompression.
Validated across many types of real-world and synthetic data.
Benchmarked for size reduction and decoding performance.
You can rely on shrink in production environments such as:
Firebase and Firestore data storage
Offline cache or local DBs
Network transmission over low bandwidth
Size-optimized APIs or backups
Performance and compression algorithms continue to improve with each release — but all 1.x.x versions of shrink maintain full backward compatibility. You’ll never need to re-compress or migrate your existing data — it will always restore correctly, regardless of how the internals evolve.
🔥 Firebase Integration Example
Storing large lists (like inventory, user items, or flags) in Firestore can get expensive — especially when using arrays of integers. With shrink, you can compress the list into a tiny Blob field, saving both space and money, while preserving full data integrity.
You can shrink this list and store it as a Firestore binary field:
import'package:cloud_firestore/cloud_firestore.dart';
import'package:shrink/shrink.dart';
final userId = 'abc123';
final compressed = items.shrink(); // or Shrink.unique(items)awaitFirebaseFirestore.instance
.collection('users')
.doc(userId)
.set({'items_blob': compressed}, SetOptions(merge: true));
📤 Restoring Data from Firestore
When you need the original list of items:
final doc = awaitFirebaseFirestore.instance
.collection('users')
.doc(userId)
.get();
final compressed = doc['items_blob'] asUint8List;
final restoredItems = compressed.restoreUnique(); // or Restore.unique(compressed)
💡 Why Use Shrink?
✅ Drastically smaller payloads (from KBs to just a few bytes)
✅ Safe and lossless — original data is perfectly restored
✅ Firestore-friendly — binary blobs are more efficient than large arrays
✅ Future-proof — compression method is encoded automatically
ℹ️ Tip: You can use this approach for storing compressed JSON, logs, flags, or anything serializable into a list or string.
🧑🏫 Beginner's Guide: Step-by-Step Setup & Usage
This guide walks you through installing and using shrink — a lightweight and powerful tool to compress your data and save space with just one line of code.
You can shrink text, JSON, byte data, or lists of IDs. It’s great for reducing payloads, speeding up storage, and minimizing Firebase costs.
✅ Step 1: Add shrink to Your Project
🔧 Option A: Use a command (easy & automatic)
In your terminal, run one of these:
flutter pub add shrink # if you're using Flutter
or
dart pub add shrink # if you're using Dart only (no Flutter)
📄 Option B: Edit pubspec.yaml manually
Open your pubspec.yaml file and add:
dependencies:shrink:^latest
Then run:
flutter pub get # for Flutter
or
dart pub get # for Dart only
That’s it! You’ve added shrink to your project.
Now you're ready to compress and restore data with just a few lines of code.
✅ Step 2: Import the Package
In your Dart/Flutter file:
import'package:shrink/shrink.dart';
This gives you access to all the .shrink() and .restoreX() functions.
✅ Step 3: Shrink Different Types of Data
You can shrink 4 types of data.
Each type has its own example — use the one that matches what you want to compress.
📦 Example 1: Shrink a String (like a message, log, or description)
final compressed = 'Hello world! This is a long message.'.shrink();
// Later, to get it back:final restored = compressed.restoreText();
🧠 Example 2: Shrink a JSON object (like user data or settings)
✅ Shrinking is automatic — it picks the best method for your data.
✅ Shrink is lossless — you always get the original data back.
✅ If the data can't be compressed, it just returns it as-is (no size increase).
❗ Make sure you use the right .restoreX() based on what you compressed.
🚀 Roadmap & Future Plans
The shrink package is actively maintained and will continue to evolve with new features, performance optimizations, and developer-friendly tools. Here's what’s coming next:
✅ In Progress
Async Compression & Decompression
Introduce AsyncShrink and AsyncRestore classes.
Add extension methods: data.asyncShrink() and data.asyncRestore().
Benefits:
Non-blocking compression for large payloads.
Ready for use in Flutter apps and backends handling large streams or network data.
File Compression Support
Shrink and restore entire files or file-like streams.
Designed for use with local storage or cloud uploads.
Will include support for:
Reading from File or Stream<List<int>>.
Writing compressed data directly to disk or Firebase.
⚡ Planned Enhancements
Improved Performance for JSON & String Compression
Optimize minification and buffer handling.
Better handling of deeply nested or repetitive JSON structures.
Custom Compression Configs
Enable fine-tuned compression strategies.
Allow developers to specify:
Preferred algorithms (e.g., prioritize speed vs. size).
Compression levels or formats (e.g., only use ZLIB).
Streamed Compression APIs
Stream in → shrink → stream out.
Ideal for use cases involving:
Real-time logs.
Chunked data uploads/downloads.
Memory-sensitive environments.
🔍 Exploratory Ideas
Custom Plugin Support
Allow registering your own shrink strategies or codecs.
Encrypted Compression Modes
Optional lightweight AES layer over compressed data.