This guide gets you from zero to compressing and decompressing data with the Zstandard Flutter plugin in a few minutes.
In your Flutter app’s pubspec.yaml:
dependencies:
zstandard: ^1.5.0Then run:
flutter pub getImport and use the main class:
import 'package:flutter/foundation.dart';
import 'package:zstandard/zstandard.dart';
void main() async {
final zstandard = Zstandard();
final data = Uint8List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// Compress with default-like level (e.g. 3)
final compressed = await zstandard.compress(data, 3);
if (compressed == null) return; // handle failure
// Decompress
final decompressed = await zstandard.decompress(compressed);
if (decompressed != null && listEquals(data, decompressed)) {
print('Roundtrip OK');
}
}Or use the extension methods on Uint8List?:
final compressed = await data.compress(compressionLevel: 3);
final decompressed = await compressed?.decompress();For a pure Dart app on macOS, Windows, or Linux (no Flutter):
dependencies:
zstandard_cli: ^1.5.0import 'package:zstandard_cli/zstandard_cli.dart';
void main() async {
final data = Uint8List.fromList([1, 2, 3, 4, 5]);
final compressed = await data.compress(compressionLevel: 3);
final decompressed = await compressed?.decompress();
}Or run the CLI from the shell:
dart run zstandard_cli:compress myfile.txt 3
dart run zstandard_cli:decompress myfile.txt.zstd- Installation — Platform-specific setup (e.g. web assets).
- Usage examples — More examples and patterns.
- Compression levels — Choose the right level for speed vs ratio.
- API — Main — Full API reference.