zstd 0.0.1-dev.2 copy "zstd: ^0.0.1-dev.2" to clipboard
zstd: ^0.0.1-dev.2 copied to clipboard

Zstandard, or zstd as short version, is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios. It's backed by a very fast entropy [...]

example/lib/main.dart

import 'dart:convert';
import 'dart:developer';

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

import 'package:zstd/zstd.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return CupertinoApp(home: HomeView());
  }
}

class HomeView extends StatelessWidget {
  const HomeView({super.key});

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            CupertinoButton(
              child: Text('ZSTD'),
              onPressed: () async {
                final input = await rootBundle
                    .load('assets/github/user.0AdXA5MNzW.json')
                    .then((e) => Uint8List.sublistView(e));
                final encoded = zstd.encode(input);
                final ratio = input.length / encoded.length;
                log('encode ratio is $ratio');
                final decoded = zstd.decode(encoded);
                log('decode length is ${decoded.length}');
                final text = utf8.decode(decoded);
                log('decode text is $text');
              },
            ),
            CupertinoButton(
              child: Text('ZSTD with dictionary'),
              onPressed: () async {
                final dictionary = await rootBundle
                    .load('assets/github.dict')
                    .then((e) => Uint8List.sublistView(e));
                final zstd = ZstdCodec(dictionary: dictionary);
                final input = await rootBundle
                    .load('assets/github/user.0AdXA5MNzW.json')
                    .then((e) => Uint8List.sublistView(e));
                final encoded = zstd.encode(input);
                final ratio = input.length / encoded.length;
                log('encode ratio with dictionary is $ratio');
                final decoded = zstd.decode(encoded);
                log('decode length is ${decoded.length}');
                final text = utf8.decode(decoded);
                log('decode text is $text');
              },
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
150
points
161
downloads

Publisher

verified publisherzeekr.dev

Weekly Downloads

Zstandard, or zstd as short version, is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios. It's backed by a very fast entropy stage, provided by Huff0 and FSE library.

Topics

#zstd

Documentation

API reference

License

MIT (license)

Dependencies

flutter, zstd_api, zstd_native

More

Packages that depend on zstd

Packages that implement zstd