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

A Dart implementation of the LZF, a fast, lightweight compression algorithm optimized for speed.

LZF is optimized for speed over compression ratio. Ideal for real-time data processing, caching layers, and low-latency systems where throughput matters most.

The data format and algorithm are based on the C library liblzf by Marc Lehmann, with the implementation adapted from the Java library compress-lzf by Tatu Saloranta.

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

🚀 Getting Started

Add the package to your pubspec.yaml:

dependencies:
  lzf: ^0.1.1

Then import it:

import 'package:lzf/lzf.dart';

⚡ Quick Example

Compress data with LZFEncoder.encode() and decompress it with LZFDecoder.decode(). Both works with Uint8List:

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');
}

🐞 Features and Bugs

If you encounter bugs or need additional functionality, please file an issue.

Libraries

lzf
This library provides a Dart implementation of the LZF, a fast and lightweight data compression algorithm.