zstandard 壓縮外掛程式的共用平台介面,可於 Android、iOS、Linux、macOS、Web 與 Windows 上一致整合 Zstandard 壓縮與解壓功能。此套件抽象化平台特定實作,讓開發者能撰寫可在所有支援平台順暢運作的統一程式碼。它作為其他 zstandard 相關套件的基礎,促進可維護性並減少重複。介面設計為可由各平台特定實作擴充,確保相容性與效能,同時維持 API 穩定。
適用情境
跨平台壓縮工具
跨平台應用中的統一資料壓縮
與基於 zstandard 的檔案處理整合
支援高效的資料儲存與傳輸
建構依賴 Zstandard 壓縮的外掛程式
主要特色
共享平台介面
多平台支援(Android、iOS、Linux、macOS、Web、Windows)
可擴展的設計,用於平台特定的實作
穩定且一致的 API
促進 Zstandard 插件開發
適合對象
開發跨平台壓縮工具的開發者
需要標準化 zstandard 接口的外掛作者
需要高效、跨平台資料壓縮的應用程式
維護多個平台建構並共享邏輯的團隊
使用建議
需要由平台特定的套件實作
沒有平台擴展無法獨立使用
依賴於底層 zstandard 庫的正確設定
在 Web 或 Windows 環境中可能需要額外的設定
原始 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();
}