The zstandard_linux package provides the Linux implementation of the Zstandard Flutter plugin using FFI and the native zstd library.
| Architecture | Support |
|---|---|
| x64 | Yes |
| arm64 | Yes |
Add the main plugin to your app; the Linux implementation is included via the federated plugin:
dependencies:
zstandard: ^1.3.29No additional setup is required for normal use. The plugin registers the Linux implementation automatically when running on Linux.
- Native layer: The facebook/zstd C library is built with CMake (e.g. under
linux/orsrc/) and produces a shared librarylibzstandard_linux_plugin.sothat the Dart plugin loads via FFI. - Dart layer: The package uses Dart FFI and generated bindings to call
ZSTD_compress,ZSTD_decompress,ZSTD_compressBound, andZSTD_getFrameContentSize. - Isolates: The implementation may use a helper isolate for async compression/decompression.
Use the main package API; the Linux implementation is used automatically:
import 'package:zstandard/zstandard.dart';
final zstandard = Zstandard();
final compressed = await zstandard.compress(data, 3);
final decompressed = await zstandard.decompress(compressed!);Or use the extensions:
final compressed = await data.compress(compressionLevel: 3);
final decompressed = await compressed?.decompress();If you are developing the zstandard_linux package:
- The native zstd source is under the package’s
src/; the Linux build is typically underlinux/using CMake. - CMake builds the shared library (e.g.
libzstandard_linux_plugin.so). - FFI bindings are generated (e.g. with
ffigen) from the zstd headers.
See the package’s linux/ and src/ directories and the repo’s Building guide.
- Unit tests: From the package directory:
flutter test - Integration tests: Run the example Linux app and execute
integration_testfrom the example.
- Compression/decompression: Typically runs in a background isolate so the UI thread is not blocked.
- Memory: Allocations scale with input and output size; high compression levels (19–22) use more memory.
- Throughput: Similar to native zstd; level 1–3 are fastest, level 22 slowest. Depends on host CPU.
- Only Linux is supported; for other platforms use the corresponding platform package.
- Very large inputs may use significant memory; consider chunking (see Advanced usage).
- The shared library must be on the library path (e.g. next to the executable or
LD_LIBRARY_PATH) when the app runs.
- libzstandard_linux_plugin.so not found: Ensure the .so is built and available in the library path when the app runs (e.g. same directory as the executable or
LD_LIBRARY_PATH). Build withflutter build linuxor run from the IDE. - Crashes: Verify inputs and null safety; see Common Issues.