zstandard_web 包为 Flutter 应用程序提供了适用于 Web 的 Zstandard 压缩算法的兼容实现。它可在浏览器中直接高效地压缩和解压数据,利用针对速度和压缩比优化的高性能 Zstandard 编码器。该包专为 Web 平台设计,确保与 Flutter 的 Web 构建流程无缝集成。开发者可通过压缩资源或数据传输来减小负载大小并提升加载速度。该包由 vyp.dev 维护,是开源项目,托管在 GitHub 上。
适合场景
压缩 Web 应用资源
减少网络负载大小
优化 Web 应用中的数据传输
提升大规模数据处理的性能
在基于浏览器的 Flutter 应用中启用快速压缩
主要特点
Web 上的 Zstandard 压缩支持
高速压缩和解压
浏览器原生性能
开源且持续维护
无缝的 Flutter Web 集成
适合对象
需要高效压缩的Flutter Web开发人员
包含大量数据负载的应用程序
性能关键的网页应用
在其他环境中使用 Zstandard 的开发者
需要轻量级、快速压缩的项目
使用建议
仅限网页平台
需要 Dart 2.12+
依赖原生 WebAssembly 以获得性能
不兼容移动或桌面平台
由于 WebAssembly 的原因,可能会增加初始包大小
原始 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();
}