Alien::Win32::LZMA - Install and make available lzma.exe


Alien-Win32-LZMA documentation Contained in the Alien-Win32-LZMA distribution.

Index


Code Index:

NAME

Top

Alien::Win32::LZMA - Install and make available lzma.exe

DESCRIPTION

Top

On Windows (unlike on Unix systems) the primary mechanism for accessing LZMA functionality is via the 7-Zip desktop application.

Alien::Win32::LZMA is a simple Alien module which embeds a copy of the lzma.exe command line utility for use in situations where the memory-only compression and decompression provided by the current generation of modules is not sufficient.

The version of lzma.exe provided by this module is taken from the LZMA SDK 4.65 at http://downloads.sourceforge.net/sevenzip/lzma465.tar.bz2.

FUNCTIONS

Top

lzma_exe

The lzma_exe function returns the location of the installed lzma.exe command line application as a string.

lzma_version

The lzma_version function runs lzma.exe and finds the version of the application. It should match the version of this module.

lzma_compress

  lzma_compress('file', 'file.lz') or die('Failed to compress');

The lzma_compress function invokes lzma.exe to compress one file into another file.

Any additional params to lzma_compress will be passed through to the underlying command line call as options.

Returns true if the invocation returns without error.

lzma_decompress

  lzma_decompress('file','file.lz') or die('Failed to decompress');

The lzma_decompress function invokes lzma.exe to decompress an LZMA file into another file.

Any additional params to lzma_compress will be passed through to the underlying command line call as options.

Returns true if the invocation returns without error.

SUPPORT

Top

Bugs should be reported via the CPAN bug tracker at

http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Alien-Win32-LZMA

For other issues, contact the author.

AUTHOR

Top

Adam Kennedy <adamk@cpan.org>

SEE ALSO

Top

Compress::umLZMA

COPYRIGHT

Top


Alien-Win32-LZMA documentation Contained in the Alien-Win32-LZMA distribution.
package Alien::Win32::LZMA;

use 5.008;
use strict;
use warnings;
use Carp                ();
use Exporter            ();
use IPC::Run3     0.042 ();
use File::ShareDir 1.00 ();

our $VERSION = '4.66';
our @ISA     = 'Exporter';

sub lzma_exe {
	File::ShareDir::dist_file('Alien-Win32-LZMA', 'lzma.exe');
}

sub lzma_version {
	my $exe    = lzma_exe();
	my $stderr = '';
	my $result = IPC::Run3::run3(
		[ $exe ],
		\undef,
		\undef,
		\$stderr,
	);
	unless ( $result ) {
		die "$exe execution failed";
	}
	unless  ( $stderr =~ /^\s*LZMA\s*([\d\.]+)/s ) {
		die "Failed to find LZMA version";
	}
	return "$1";
}

sub lzma_compress {
	my $from = shift;
	my $to   = shift;
	my $cmd  = lzma_exe();
	unless ( -f $from ) {
		Carp::croak("No such file or directory '$from'");
	}
	IPC::Run3::run3(
		[ $cmd, 'e', $from, $to, @_ ],
		\undef, \undef, \undef,
	);
}

sub lzma_decompress {
	my $from = shift;
	my $to   = shift;
	my $cmd  = lzma_exe();
	unless ( -f $from ) {
		Carp::croak("No such file or directory '$from'");
	}
	IPC::Run3::run3(
		[ $cmd, 'd', $from, $to, @_ ],
		\undef, \undef, \undef,
	);
}

1;