Compress::unLZMA - Interface to LZMA decompression library


Compress-unLZMA documentation Contained in the Compress-unLZMA distribution.

Index


Code Index:

NAME

Top

Compress::unLZMA - Interface to LZMA decompression library

SYNOPSIS

Top

  use Compress::unLZMA qw(uncompress uncompressfile);
  my $data = uncompressfile('foo.lzma');
  my $data = uncompress($content);

DESCRIPTION

Top

LZMA is default and general compression method of 7z format in 7-Zip program. LZMA provides high compression ratio and very fast decompression.

This module is based on the LZMA SDK which provides a cross-platform implementation of the LZMA decompression algorithm in ANSI C.

From SDK lzma.txt file:

  LZMA decompression code was ported from original C++ sources to C.
  Also it was simplified and optimized for code size.
  But it is fully compatible with LZMA from 7-Zip.

METHODS

Top

$data = uncompress($content)

Uncompress $data. if successfull, it returns the uncompressed data. Otherwise it returns undef and $@ contains the error message.

The source buffer can be either be a scalar or a scalar reference.

$data = uncompressfile($file)

Uncompress the file $file. if successfull, it returns the uncompressed data. Otherwise it returns undef and $@ contains the error message.

CAVEATS

Top

This version only implements in-memory decompression (patches are welcomed).

There is no way to recognize a valid LZMA encoded file with the SDK. So, in some cases, you can crash your script if you try to uncompress a non valid LZMA encoded file.

REQUESTS & BUGS

Top

Please report any requests, suggestions or bugs via the RT bug-tracking system at http://rt.cpan.org/ or email to bug-Compress-unLZMA\@rt.cpan.org.

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Compress-unLZMA is the RT queue for Compress::unLZMA. Please check to see if your bug has already been reported.

MAINTAINER

Top

Adriano Ferreira, ferreira@cpan.org

COPYRIGHT

Top

LZMA COPYRIGHT

Top

SEE ALSO

Top

perl(1), http://www.7-zip.org/.


Compress-unLZMA documentation Contained in the Compress-unLZMA distribution.

package Compress::unLZMA;

use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);

our %EXPORT_TAGS = ( 'all' => [ qw(
	uncompress uncompressfile
) ] );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our $VERSION = '0.04';

require XSLoader;
XSLoader::load('Compress::unLZMA', $VERSION);

sub compress {
	die "not implemented!\n";
}

sub compressfile {
	die "not implemented!\n";
}

sub uncompress {
	my ($data) = @_;

	return undef if (length($data) < 14);

	my $properties = substr($data, 0, 5);

	my $size = 0;
	for (my $ii = 0; $ii < 4; $ii++) {
		my $b = ord(substr($data, $ii + 5, 1));
		$size += $b << ($ii * 8);
	}

	for (my $ii = 0; $ii < 4; $ii++) {
		my $b = ord(substr($data, $ii + 9, 1));
		if ($b != 0) {
			return undef;
		}
	}

	if (ord(substr($properties, 0, 1)) >= (9 * 5 * 5)) {
		return undef;
	}

	if ( $size == 0 ) { # empty file: no data to uncompress
		return '';
	}

	$data = substr($data, 13);

	my $result = uncompressdata($data, length($data), $size, $properties);

	return $result;
}

1;

__END__