Skip to content

Latest commit

 

History

History
82 lines (59 loc) · 1.88 KB

File metadata and controls

82 lines (59 loc) · 1.88 KB

Getting Started

This guide gets you from zero to compressing and decompressing data with the Zstandard Flutter plugin in a few minutes.

Add the dependency

In your Flutter app’s pubspec.yaml:

dependencies:
  zstandard: ^1.5.0

Then run:

flutter pub get

Basic usage

Import 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();

Command-line (CLI)

For a pure Dart app on macOS, Windows, or Linux (no Flutter):

dependencies:
  zstandard_cli: ^1.5.0
import '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

Next steps