zstandard_native 包通过 Flutter 外部函数接口(FFI)绑定,提供了 zstd 压缩算法的原生 C 实现。它为跨多个平台(包括 Android、iOS、Linux、macOS 和 Windows)的 Flutter 应用程序提供高性能的压缩和解压缩功能。通过利用原始的 zstd C 库,该包实现了高效的数据压缩,具有低内存开销和快速处理速度。该包非常适合处理大型文件或流式数据,在性能和效率至关重要的场景中表现优异。它可通过简单的 pub 依赖项无缝集成到 Flutter 项目中。
适合场景
移动应用中的高速数据压缩
高效的文件存储优化
实时数据流传输,带宽占用更少
桌面应用程序中的大规模数据处理
备份和归档解决方案
主要特点
原生 zstd C 库集成
跨平台支持(Android、iOS、Linux、macOS、Windows)
高性能压缩/解压
低内存占用
基于 FFI 的 Dart 绑定,实现无缝集成
适合对象
性能关键型应用
数据密集型移动和桌面应用
需要高效文件压缩的应用程序
需要直接访问 zstd 功能的开发者
注重速度和效率的项目
使用建议
每个平台都需要原生编译
由于原生二进制文件,可能导致应用体积增大
仅限 zstd 特定的压缩需求
调试原生代码时可能出现的复杂性
对外部 C 库的依赖维护
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Zstandard
Zstandard (zstd) is a fast, high-compression algorithm developed by Meta (formerly Facebook) designed for real-time compression scenarios. It offers a flexible range of compression levels, allowing both high-speed and high-ratio compression, making it ideal for applications with diverse performance needs. Zstandard is widely used in data storage, transmission, and backup solutions.
This repository contains a federated Flutter plugin and a CLI package for zstandard compression, enabling both in-app and command-line usage. The two main components are:
zstandard: A Flutter plugin for cross-platform compression, supporting mobile, desktop, and web platforms. This package integrates the zstd library through FFI for native platforms and WebAssembly for the web, allowing efficient data compression in any Flutter environment.
zstandard_cli: A pure Dart package providing CLI capabilities for macOS, Windows, and Linux. It enables command-line compression and decompression for data files and streams.
Native platform packages and the CLI share the zstd C source and FFI bindings via the zstandard_native package (zstandard_native/src/zstd/). zstandard_native is published to pub.dev as part of this repo’s release set, so a single copy is used whether you depend on the plugin from the repo or from pub.dev.
# Compress a file with a specified compression level
dart run zstandard_cli:compress --level 3 myfile.txt
# Decompress a file
dart run zstandard_cli:decompress myfile.txt.zstd
Dart Code Example (CLI)
import'package:zstandard_cli/zstandard_cli.dart';
voidmain() async {
var cli = ZstandardCLI();
final originalData = Uint8List.fromList([...]);
final compressed = await cli.compress(originalData, compressionLevel: 3);
final decompressed = await cli.decompress(compressed ?? Uint8List(0));
}
Using extensions in Dart:
import'package:zstandard_cli/zstandard_cli.dart';
voidmain() async {
final originalData = Uint8List.fromList([...]);
final compressed = await originalData.compress(compressionLevel: 3);
final decompressed = await compressed.decompress();
}