Port of LZMA compression algorithm to Dart
Dart
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
licenses
CHANGELOG.md
LICENSE.txt
README.md
pubspec.yaml

README.md

dart-lzma is a port of LZMA compression algorithm to Dart.

The source code is a manual translation from the original Java version found on the LZMA SDK.

How to use it?

If you want to compress data then just call to the compress function:

import "package:lzma/lzma.dart" as LZMA;

var input = new LZMA.InStream(<PUT YOUR DATA BUFFER HERE>);
var output = new LZMA.OutStream();
LZMA.compress(input, output);

//output.data has now your compressed data

If you want to decompress data then just call to the decompress function:

import "package:lzma/lzma.dart" as LZMA;

var input = new LZMA.InStream(<PUT YOUR LZMA DATA BUFFER HERE>);
var output = new LZMA.OutStream();
LZMA.decompress(input, output);

//output.data has now your uncompressed data

Where:

  • input is the input data stream
  • output is the output data stream

Streams

Current stream classes will be change in the future.

Examples

Compress a file and write the result to another one:

import "dart:io";
import "package:lzma/lzma.dart" as LZMA;

void main(List<String> args) {
  if (args.length != 2) {
    print("Usage: compress input output");
    return;
  }

  var inFile = new File(args[0]);
  var outFile = new File(args[1]);

  var input = new LZMA.InStream(inFile.readAsBytesSync());
  var output = new LZMA.OutStream();

  LZMA.compress(input, output);

  outFile.writeAsBytesSync(output.data);
}

Decompress a file and write the result to another one:

import "dart:io";
import "package:lzma/lzma.dart" as LZMA;

void main(List<String> args) {
  if (args.length != 2) {
    print("Usage: decompress input output");
    return;
  }

  var inFile = new File(args[0]);
  var outFile = new File(args[1]);

  var input = new LZMA.InStream(inFile.readAsBytesSync());
  var output = new LZMA.OutStream();

  LZMA.decompress(input, output);

  outFile.writeAsBytesSync(output.data);
}

Performance

Be sure to run the library in production mode (not checked mode) with debugging disabled.

Limitations

  • Output data size is limited to 32 bits.