lzma 0.3.0 lzma: ^0.3.0 copied to clipboard
LZMA compression library.
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 streamoutput
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.