Skip to content

A Dart implementation of the LZF, a fast and lightweight data compression algorithm.

License

Notifications You must be signed in to change notification settings

halildurmus/lzf

ci Package: lzf Publisher: halildurmus.dev Language: Dart License: BSD-3-Clause codecov

A Dart implementation of the LZF, a fast and lightweight data compression algorithm.

LZF is optimized for speed rather than achieving the highest compression ratios, making it ideal for scenarios where performance is the priority, such as real-time data processing and low-latency systems.

The data format and algorithm is based on the C library liblzf by Marc Lehmann and the implementation is based on the Java library compress-lzf by Tatu Saloranta.

For more details about the LZF data format, refer to the LZF Format Specification.

Usage

To use the lzf package, import it into your Dart project and follow the example below:

import 'dart:convert';

import 'package:lzf/lzf.dart';

void main() {
  // A text with repeated patterns for better compression.
  const originalText =
      'LZF compression is fast and efficient. '
      'Fast and efficient compression is useful. '
      'Useful compression is fast and efficient. '
      'Efficient and fast compression is useful. '
      'Compression is fast, efficient, and useful.';

  // Convert the text into a UTF-8 encoded byte list.
  final originalData = utf8.encode(originalText);
  print('Original text: $originalText');
  print('Original size: ${originalData.length} bytes');

  // Compress the byte data using LZF.
  final compressedData = LZFEncoder.encode(originalData);
  print('Compressed size: ${compressedData.length} bytes');
  final compressionRatio =
      (1 - (compressedData.length / originalData.length)) * 100;
  print('Compression ratio: ${compressionRatio.toStringAsFixed(2)}%');

  // Decompress the compressed data back to its original form.
  final decompressedData = LZFDecoder.decode(compressedData);
  print('Decompressed size: ${decompressedData.length} bytes');

  // Convert the decompressed byte list back into a string.
  final decompressedText = utf8.decode(decompressedData);
  print('Decompressed text: $decompressedText');
}

Feature requests and bugs

Please file feature requests and bugs at the issue tracker.

About

A Dart implementation of the LZF, a fast and lightweight data compression algorithm.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Languages