xxhash 1.1.0 copy "xxhash: ^1.1.0" to clipboard
xxhash: ^1.1.0 copied to clipboard

A FFI plugin package that implements xxHash, inspired by crypto.

A FFI plugin package that implements xxHash, inspired by crypto.

The following hashing algorithms are supported:

  • XXH32
  • XXH64
  • XXH3 (XXH3-64, XXH3-128)

Usage #

Digest on a single input #

To hash a list of bytes, invoke the convert method on the xxh32, xxh64 or xxh3 objects.

import 'package:xxhash/xxhash.dart';
import 'dart:convert'; // for the utf8.encode method

void main() {
  var bytes = utf8.encode("foobar"); // data being hashed

  var digest = xxh32.convert(bytes);

  print("Digest as bytes: ${digest.bytes}");
  print("Digest as hex string: $digest");
}

Digest on chunked input #

If the input data is not available as a single list of bytes, or needs to be chunked, use the chunked conversion approach.

Invoke the startChunkedConversion method to create a sink for the input data. On the sink, invoke the add method for each chunk of input data, and invoke the close method when all the chunks have been added. The digest can then be retrieved from the Sink<Digest> used to create the input data sink.

import 'dart:convert';

import 'package:convert/convert.dart';
import 'package:xxhash/xxhash.dart';

void main() {
  var firstChunk = utf8.encode("foo");
  var secondChunk = utf8.encode("bar");

  var output = AccumulatorSink<Digest>();
  var input = xxh32.startChunkedConversion(output);
  input.add(firstChunk);
  input.add(secondChunk); // call `add` for every chunk of input data
  input.close();
  var digest = output.events.single;

  print("Digest as bytes: ${digest.bytes}");
  print("Digest as hex string: $digest");
}

The above example uses the AccumulatorSink class that comes with the convert package. It is capable of accumulating multiple events, but in this usage only a single Digest is added to it when the data sink's close method is invoked.

For Dart only projects #

The shared dynamic library is not built when using dart alone without Flutter. For these circumstances, you can download the following pre-compiled dynamic libraries from Latest Release.

Linux #

Download libxxhash.so and add it to LD_LIBRARY_PATH environment variable:

export LD_LIBRARY_PATH=<path/to/folder/lib>:$LD_LIBRARY_PATH

This command sets your LD_LIBRARY_PATH variable for the current terminal window only. To permanently add LD_LIBRARY_PATH to your path think to create an /etc/environment.

Windows #

Download libxxhash32.dll, or libxxhash64.dll, based on your windows architecture and add it to the PATH environment:

setx PATH <path/to/folder/lib>
3
likes
0
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

A FFI plugin package that implements xxHash, inspired by crypto.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ffi, plugin_platform_interface

More

Packages that depend on xxhash