<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
package Compress::Raw::Lzma;

use strict ;
use warnings ;

require 5.006 ;
require Exporter;
use AutoLoader;
use Carp ;

use bytes ;
our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD);

$VERSION = '2.063';
$XS_VERSION = $VERSION; 
$VERSION = eval $VERSION;

@ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw(
    
    LZMA_OK
    LZMA_STREAM_END
    LZMA_NO_CHECK       	
    LZMA_UNSUPPORTED_CHECK
    LZMA_GET_CHECK
    LZMA_MEM_ERROR
    LZMA_MEMLIMIT_ERROR
    LZMA_FORMAT_ERROR
    LZMA_OPTIONS_ERROR
    LZMA_DATA_ERROR
    LZMA_BUF_ERROR
    LZMA_PROG_ERROR

    LZMA_RUN
    LZMA_SYNC_FLUSH
    LZMA_FULL_FLUSH
    LZMA_FINISH

    LZMA_FILTER_X86
    LZMA_FILTER_POWERPC
    LZMA_FILTER_IA64
    LZMA_FILTER_ARM
    LZMA_FILTER_ARMTHUMB
    LZMA_FILTER_SPARC


    LZMA_BLOCK_HEADER_SIZE_MIN
    LZMA_BLOCK_HEADER_SIZE_MAX

    LZMA_CHECK_NONE
    LZMA_CHECK_CRC32
    LZMA_CHECK_CRC64
    LZMA_CHECK_SHA256

    LZMA_CHECK_ID_MAX
    LZMA_CHECK_SIZE_MAX

    LZMA_PRESET_DEFAULT
    LZMA_PRESET_LEVEL_MASK
    LZMA_PRESET_EXTREME

    LZMA_TELL_NO_CHECK
    LZMA_TELL_UNSUPPORTED_CHECK
    LZMA_TELL_ANY_CHECK
    LZMA_CONCATENATED


    LZMA_FILTER_DELTA
    LZMA_DELTA_DIST_MIN
    LZMA_DELTA_DIST_MAX
    LZMA_DELTA_TYPE_BYTE

    LZMA_FILTERS_MAX

    LZMA_FILTER_LZMA2

    LZMA_MF_HC3
    LZMA_MF_HC4
    LZMA_MF_BT2
    LZMA_MF_BT3
    LZMA_MF_BT4

    LZMA_MODE_FAST
    LZMA_MODE_NORMAL

    LZMA_DICT_SIZE_MIN
    LZMA_DICT_SIZE_DEFAULT

    LZMA_LCLP_MIN
    LZMA_LCLP_MAX
    LZMA_LC_DEFAULT

    LZMA_LP_DEFAULT

    LZMA_PB_MIN
    LZMA_PB_MAX
    LZMA_PB_DEFAULT

    LZMA_STREAM_HEADER_SIZE

    LZMA_BACKWARD_SIZE_MIN

    LZMA_FILTER_SUBBLOCK

    LZMA_SUBFILTER_NONE		
    LZMA_SUBFILTER_SET		
    LZMA_SUBFILTER_RUN		
    LZMA_SUBFILTER_FINISH	

    LZMA_SUBBLOCK_ALIGNMENT_MIN
    LZMA_SUBBLOCK_ALIGNMENT_MAX
    LZMA_SUBBLOCK_ALIGNMENT_DEFAULT

    LZMA_SUBBLOCK_DATA_SIZE_MIN
    LZMA_SUBBLOCK_DATA_SIZE_MAX
    LZMA_SUBBLOCK_DATA_SIZE_DEFAULT

    LZMA_SUBBLOCK_RLE_OFF
    LZMA_SUBBLOCK_RLE_MIN
    LZMA_SUBBLOCK_RLE_MAX

    LZMA_VERSION
    LZMA_VERSION_MAJOR
    LZMA_VERSION_MINOR
    LZMA_VERSION_PATCH
    LZMA_VERSION_STABILITY

    LZMA_VERSION_STABILITY_STRING
    LZMA_VERSION_STRING
    );

    #LZMA_VLI_MAX
    #LZMA_VLI_UNKNOWN
    #LZMA_VLI_BYTES_MAX

sub AUTOLOAD {
    my($constname);
    ($constname = $AUTOLOAD) =~ s/.*:://;
    my ($error, $val) = constant($constname);
    Carp::croak $error if $error;
    no strict 'refs';
    *{$AUTOLOAD} = sub { $val };
    goto &amp;{$AUTOLOAD};

}

use constant FLAG_APPEND             =&gt; 1 ;
use constant FLAG_CRC                =&gt; 2 ;
use constant FLAG_ADLER              =&gt; 4 ;
use constant FLAG_CONSUME_INPUT      =&gt; 8 ;
use constant FLAG_LIMIT_OUTPUT       =&gt; 16 ;

eval {
    require XSLoader;
    XSLoader::load('Compress::Raw::Lzma', $XS_VERSION);
    1;
} 
or do {
    require DynaLoader;
    local @ISA = qw(DynaLoader);
    bootstrap Compress::Raw::Lzma $XS_VERSION ; 
};

use constant Parse_any      =&gt; 0x01;
use constant Parse_unsigned =&gt; 0x02;
use constant Parse_signed   =&gt; 0x04;
use constant Parse_boolean  =&gt; 0x08;
use constant Parse_string   =&gt; 0x10;
use constant Parse_custom   =&gt; 0x12;

use constant Parse_store_ref =&gt; 0x100 ;

use constant OFF_PARSED     =&gt; 0 ;
use constant OFF_TYPE       =&gt; 1 ;
use constant OFF_DEFAULT    =&gt; 2 ;
use constant OFF_FIXED      =&gt; 3 ;
use constant OFF_FIRST_ONLY =&gt; 4 ;
use constant OFF_STICKY     =&gt; 5 ;



sub ParseParameters
{
    my $level = shift || 0 ; 

    my $sub = (caller($level + 1))[3] ;
    #local $Carp::CarpLevel = 1 ;
    my $p = new Compress::Raw::Lzma::Parameters() ;
    $p-&gt;parse(@_)
        or croak "$sub: $p-&gt;{Error}" ;

    return $p;
}


sub Compress::Raw::Lzma::Parameters::new
{
    my $class = shift ;

    my $obj = { Error =&gt; '',
                Got   =&gt; {},
              } ;

    #return bless $obj, ref($class) || $class || __PACKAGE__ ;
    return bless $obj, 'Compress::Raw::Lzma::Parameters' ;
}

sub Compress::Raw::Lzma::Parameters::setError
{
    my $self = shift ;
    my $error = shift ;
    my $retval = @_ ? shift : undef ;

    $self-&gt;{Error} = $error ;
    return $retval;
}
          
#sub getError
#{
#    my $self = shift ;
#    return $self-&gt;{Error} ;
#}
          
sub Compress::Raw::Lzma::Parameters::parse
{
    my $self = shift ;

    my $default = shift ;

    my $got = $self-&gt;{Got} ;
    my $firstTime = keys %{ $got } == 0 ;

    my (@Bad) ;
    my @entered = () ;

    # Allow the options to be passed as a hash reference or
    # as the complete hash.
    if (@_ == 0) {
        @entered = () ;
    }
    elsif (@_ == 1) {
        my $href = $_[0] ;    
        return $self-&gt;setError("Expected even number of parameters, got 1")
            if ! defined $href or ! ref $href or ref $href ne "HASH" ;
 
        foreach my $key (keys %$href) {
            push @entered, $key ;
            push @entered, \$href-&gt;{$key} ;
        }
    }
    else {
        my $count = @_;
        return $self-&gt;setError("Expected even number of parameters, got $count")
            if $count % 2 != 0 ;
        
        for my $i (0.. $count / 2 - 1) {
            push @entered, $_[2* $i] ;
            push @entered, \$_[2* $i+1] ;
        }
    }


    while (my ($key, $v) = each %$default)
    {
        croak "need 4 params [@$v]"
            if @$v != 4 ;

        my ($first_only, $sticky, $type, $value) = @$v ;
        my $x ;
        $self-&gt;_checkType($key, \$value, $type, 0, \$x) 
            or return undef ;

        $key = lc $key;

        if ($firstTime || ! $sticky) {
            $got-&gt;{$key} = [0, $type, $value, $x, $first_only, $sticky] ;
        }

        $got-&gt;{$key}[OFF_PARSED] = 0 ;
    }

    for my $i (0.. @entered / 2 - 1) {
        my $key = $entered[2* $i] ;
        my $value = $entered[2* $i+1] ;

        #print "Key [$key] Value [$value]" ;
        #print defined $$value ? "[$$value]\n" : "[undef]\n";

        $key =~ s/^-// ;
        my $canonkey = lc $key;
 
        if ($got-&gt;{$canonkey} &amp;&amp; ($firstTime ||
                                  ! $got-&gt;{$canonkey}[OFF_FIRST_ONLY]  ))
        {
            my $type = $got-&gt;{$canonkey}[OFF_TYPE] ;
            my $s ;
            $self-&gt;_checkType($key, $value, $type, 1, \$s)
                or return undef ;
            #$value = $$value unless $type &amp; Parse_store_ref ;
            $value = $$value ;
            $got-&gt;{$canonkey} = [1, $type, $value, $s] ;
        }
        else
          { push (@Bad, $key) }
    }
 
    if (@Bad) {
        my ($bad) = join(", ", @Bad) ;
        return $self-&gt;setError("unknown key value(s) @Bad") ;
    }

    return 1;
}

sub Compress::Raw::Lzma::Parameters::_checkType
{
    my $self = shift ;

    my $key   = shift ;
    my $value = shift ;
    my $type  = shift ;
    my $validate  = shift ;
    my $output  = shift;

    #local $Carp::CarpLevel = $level ;
    #print "PARSE $type $key $value $validate $sub\n" ;
    if ( $type &amp; Parse_store_ref)
    {
        #$value = $$value
        #    if ref ${ $value } ;

        $$output = $value ;
        return 1;
    }

    $value = $$value ;

    if ($type &amp; Parse_any)
    {
        $$output = $value ;
        return 1;
    }
    elsif ($type &amp; Parse_unsigned)
    {
        return $self-&gt;setError("Parameter '$key' must be an unsigned int, got 'undef'")
            if $validate &amp;&amp; ! defined $value ;
        return $self-&gt;setError("Parameter '$key' must be an unsigned int, got '$value'")
            if $validate &amp;&amp; $value !~ /^\d+$/;

        $$output = defined $value ? $value : 0 ;    
        return 1;
    }
    elsif ($type &amp; Parse_signed)
    {
        return $self-&gt;setError("Parameter '$key' must be a signed int, got 'undef'")
            if $validate &amp;&amp; ! defined $value ;
        return $self-&gt;setError("Parameter '$key' must be a signed int, got '$value'")
            if $validate &amp;&amp; $value !~ /^-?\d+$/;

        $$output = defined $value ? $value : 0 ;    
        return 1 ;
    }
    elsif ($type &amp; Parse_boolean)
    {
        return $self-&gt;setError("Parameter '$key' must be an int, got '$value'")
            if $validate &amp;&amp; defined $value &amp;&amp; $value !~ /^\d*$/;
        $$output =  defined $value ? $value != 0 : 0 ;    
        return 1;
    }
    elsif ($type &amp; Parse_string)
    {
        $$output = defined $value ? $value : "" ;    
        return 1;
    }

    $$output = $value ;
    return 1;
}



sub Compress::Raw::Lzma::Parameters::parsed
{
    my $self = shift ;
    my $name = shift ;

    return $self-&gt;{Got}{lc $name}[OFF_PARSED] ;
}

sub Compress::Raw::Lzma::Parameters::value
{
    my $self = shift ;
    my $name = shift ;

    if (@_)
    {
        $self-&gt;{Got}{lc $name}[OFF_PARSED]  = 1;
        $self-&gt;{Got}{lc $name}[OFF_DEFAULT] = $_[0] ;
        $self-&gt;{Got}{lc $name}[OFF_FIXED]   = $_[0] ;
    }

    return $self-&gt;{Got}{lc $name}[OFF_FIXED] ;
}


sub Compress::Raw::Lzma::Encoder::STORABLE_freeze
{
    my $type = ref shift;
    croak "Cannot freeze $type object\n";
}

sub Compress::Raw::Lzma::Encoder::STORABLE_thaw
{
    my $type = ref shift;
    croak "Cannot thaw $type object\n";
}


@Compress::Raw::Lzma::EasyEncoder::ISA = qw(Compress::Raw::Lzma::Encoder);

sub Compress::Raw::Lzma::EasyEncoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
            {
                'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],
 
                'Preset'        =&gt; [1, 1, Parse_unsigned, LZMA_PRESET_DEFAULT()],
                'Extreme'       =&gt; [1, 1, Parse_boolean, 0],
                'Check'         =&gt; [1, 1, Parse_unsigned, LZMA_CHECK_CRC32()],
            }, @_) ;


#    croak "Compress::Raw::Lzma::EasyEncoder::new: Bufsize must be &gt;= 1, you specified " . 
#            $got-&gt;value('Bufsize')
#        unless $got-&gt;value('Bufsize') &gt;= 1;

    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;

    my $preset = $got-&gt;value('Preset');

    if ($got-&gt;value('Extreme')) {
        $preset |= LZMA_PRESET_EXTREME();
    }

    lzma_easy_encoder($pkg, $flags,
                $got-&gt;value('Bufsize'), 
                $preset,
                $got-&gt;value('Check')) ;

}

@Compress::Raw::Lzma::AloneEncoder::ISA = qw(Compress::Raw::Lzma::Encoder);

sub Compress::Raw::Lzma::AloneEncoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
            {
                'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],
                'Filter'        =&gt; [1, 1, Parse_any, [] ],
 
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;

    my $filters = Lzma::Filters::validateFilters(1, 0, $got-&gt;value('Filter')) ;
    # TODO - check max of 1 filter &amp; it is a reference to Lzma::Filter::Lzma1

    lzma_alone_encoder($pkg, $flags, 
                       $got-&gt;value('Bufsize'),
                       $filters);

}

@Compress::Raw::Lzma::StreamEncoder::ISA = qw(Compress::Raw::Lzma::Encoder);

sub Compress::Raw::Lzma::StreamEncoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
            {
                'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],
                'Filter'        =&gt; [1, 1, Parse_any, [] ],
                'Check'         =&gt; [1, 1, Parse_unsigned, LZMA_CHECK_CRC32()],
 
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;

    my $filters = Lzma::Filters::validateFilters(1, 1, $got-&gt;value('Filter')) ;

    lzma_stream_encoder($pkg, $flags, 
                        $got-&gt;value('Bufsize'),
                        $filters,
                        $got-&gt;value('Check'));

}

@Compress::Raw::Lzma::RawEncoder::ISA = qw(Compress::Raw::Lzma::Encoder);

sub Compress::Raw::Lzma::RawEncoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
            {
                'ForZip'        =&gt; [1, 1, Parse_boolean,  0],
                'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],
                'Filter'        =&gt; [1, 1, Parse_any, [] ],
 
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;

    my $forZip = $got-&gt;value('ForZip');

    my $filters = Lzma::Filters::validateFilters(1, ! $forZip, $got-&gt;value('Filter')) ;

    lzma_raw_encoder($pkg, $flags, 
                        $got-&gt;value('Bufsize'),
                        $filters, 
                        $forZip);

}

@Compress::Raw::Lzma::AutoDecoder::ISA = qw(Compress::Raw::Lzma::Decoder);

sub Compress::Raw::Lzma::AutoDecoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
                    {
                        'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                        'LimitOutput'   =&gt; [1, 1, Parse_boolean,  0],
                        'ConsumeInput'  =&gt; [1, 1, Parse_boolean,  1],
                        'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],

                        'MemLimit'      =&gt; [1, 1, Parse_unsigned, 128 *1024 *1024],
                 
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;
    $flags |= FLAG_CONSUME_INPUT if $got-&gt;value('ConsumeInput') ;
    $flags |= FLAG_LIMIT_OUTPUT if $got-&gt;value('LimitOutput') ;

    lzma_auto_decoder($pkg, $flags, $got-&gt;value('MemLimit'));
}

@Compress::Raw::Lzma::AloneDecoder::ISA = qw(Compress::Raw::Lzma::Decoder);

sub Compress::Raw::Lzma::AloneDecoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
                    {
                        'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                        'LimitOutput'   =&gt; [1, 1, Parse_boolean,  0],
                        'ConsumeInput'  =&gt; [1, 1, Parse_boolean,  1],
                        'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],

                        'MemLimit'      =&gt; [1, 1, Parse_unsigned, 128 *1024 *1024],
                 
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;
    $flags |= FLAG_CONSUME_INPUT if $got-&gt;value('ConsumeInput') ;
    $flags |= FLAG_LIMIT_OUTPUT if $got-&gt;value('LimitOutput') ;

    lzma_alone_decoder($pkg, 
                       $flags, 
                       $got-&gt;value('Bufsize'),
                       $got-&gt;value('MemLimit'));
}

@Compress::Raw::Lzma::StreamDecoder::ISA = qw(Compress::Raw::Lzma::Decoder);

sub Compress::Raw::Lzma::StreamDecoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
                    {
                        'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                        'LimitOutput'   =&gt; [1, 1, Parse_boolean,  0],
                        'ConsumeInput'  =&gt; [1, 1, Parse_boolean,  1],
                        'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],

                        'MemLimit'      =&gt; [1, 1, Parse_unsigned, 128 *1024 *1024],
                        'Flags'         =&gt; [1, 1, Parse_unsigned, 0],
                 
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;
    $flags |= FLAG_CONSUME_INPUT if $got-&gt;value('ConsumeInput') ;
    $flags |= FLAG_LIMIT_OUTPUT if $got-&gt;value('LimitOutput') ;

    lzma_stream_decoder($pkg, 
                        $flags, 
                        $got-&gt;value('Bufsize'), 
                        $got-&gt;value('MemLimit'), 
                        $got-&gt;value('Flags'));
}

@Compress::Raw::Lzma::RawDecoder::ISA = qw(Compress::Raw::Lzma::Decoder);

sub Compress::Raw::Lzma::RawDecoder::new
{
    my $pkg = shift ;
    my ($got) = ParseParameters(0,
                    {
                        'AppendOutput'  =&gt; [1, 1, Parse_boolean,  0],
                        'LimitOutput'   =&gt; [1, 1, Parse_boolean,  0],
                        'ConsumeInput'  =&gt; [1, 1, Parse_boolean,  1],
                        'Bufsize'       =&gt; [1, 1, Parse_unsigned, 16 * 1024],
                        'Filter'        =&gt; [1, 1, Parse_any, [] ],
                        'Properties'    =&gt; [1, 1, Parse_any,  undef],
            }, @_) ;


    my $flags = 0 ;
    $flags |= FLAG_APPEND if $got-&gt;value('AppendOutput') ;
    $flags |= FLAG_CONSUME_INPUT if $got-&gt;value('ConsumeInput') ;
    $flags |= FLAG_LIMIT_OUTPUT if $got-&gt;value('LimitOutput') ;

    my $filters = Lzma::Filters::validateFilters(0, ! defined $got-&gt;value('Properties'), 
                            $got-&gt;value('Filter')) ;

    lzma_raw_decoder($pkg, 
                        $flags, 
                        $got-&gt;value('Bufsize'), 
                        $filters,
                        $got-&gt;value('Properties'));
}

# LZMA1/2
#   Preset
#   Dict
#   Lc
#   Lp
#   Pb
#   Mode LZMA_MODE_FAST, LZMA_MODE_NORMAL
#   Nice
#   Mf LZMA_MF_HC3 LZMA_MF_HC4 LZMA_MF_BT2 LZMA_MF_BT3 LZMA_MF_BT4 
#   Depth

# BCJ
#   LZMA_FILTER_X86
#   LZMA_FILTER_POWERPC
#   LZMA_FILTER_IA64
#   LZMA_FILTER_ARM
#   LZMA_FILTER_ARMTHUMB
#   LZMA_FILTER_SPARC
#
#   BCJ =&gt; LZMA_FILTER_X86 -- this assumes offset is 0
#   BCJ =&gt; [LZMA_FILTER_X86, offset]

# Delta
#    Dist 1 - 256, 1

# Subblock
#    Size
#    RLE
#    Align

# Preset (0-9) LZMA_PRESET_EXTREME LZMA_PRESET_DEFAULT -- call lzma_lzma_preset

# Memory

# Check =&gt; LZMA_CHECK_NONE, LZMA_CHECK_CRC32, LZMA_CHECK_CRC64, LZMA_CHECK_SHA256

# my $bool = lzma_check_is_supported(LZMA_CHECK_CRC32);
# my $int = lzma_check_size(LZMA_CHECK_CRC32);
# my $int = $lzma-&gt;lzma_get_check();




#sub Compress::Raw::Lzma::new
#{
#    my $class = shift ;
#    my ($ptr, $status) = _new(@_);
#    return wantarray ? (undef, $status) : undef
#        unless $ptr ;
#    my $obj = bless [$ptr], $class ;
#    return wantarray ? ($obj, $status) : $obj;
#}
#
#package Compress::Raw::UnLzma ;
#
#sub Compress::Raw::UnLzma::new
#{
#    my $class = shift ;
#    my ($ptr, $status) = _new(@_);
#    return wantarray ? (undef, $status) : undef
#        unless $ptr ;
#    my $obj = bless [$ptr], $class ;
#    return wantarray ? ($obj, $status) : $obj;
#}


sub Lzma::Filters::validateFilters
{
    use UNIVERSAL ;
    use Scalar::Util qw(blessed );

    my $encoding = shift; # not decoding
    my $lzma2 = shift; 

    my $objType = $lzma2 ? "Lzma::Filter::Lzma2"
                         : "Lzma::Filter::Lzma" ;

    # if only one, convert into an array reference
    if (blessed $_[0] )  {
        die "filter object $_[0] is not an $objType object" 
            unless UNIVERSAL::isa($_[0], $objType);

            #$_[0] = [ $_[0] ] ;
        return [ $_[0] ] ;
    }

    if (ref $_[0] ne 'ARRAY')
      { die "$_[0] not Lzma::Filter object or ARRAY ref" }

    my $filters = $_[0] ;
    my $count = @$filters;

    # check number of filters
    die sprintf "Too many filters ($count), max is %d", LZMA_FILTERS_MAX()
        if $count &gt; LZMA_FILTERS_MAX();

    # TODO - add more tests here
    # Check that all filters inherit from Lzma::Filter
    # check that filters are supported
    # check memory requirements
    # need exactly one lzma1/2 filter
    # lzma1/2 is the last thing in the list 
    for (my $i = 0; $i &lt;  @$filters ; ++$i)
    {
        my $filt = $filters-&gt;[$i];
        die "filter is not an Lzma::Filter object" 
            unless UNIVERSAL::isa($filt, 'Lzma::Filter');
        die "Lzma filter must be last" 
            if UNIVERSAL::isa($filt, 'Lzma::Filter::Lzma') &amp;&amp; $i &lt; $count -1 ;

        #die "xxx" unless lzma_filter_encoder_is_supported($filt-&gt;id());
    }

    if (@$filters == 0)
    {
        push @$filters, $lzma2 ? Lzma::Filter::Lzma2()
                               : Lzma::Filter::Lzma1();
    }

    return $filters;
}

#package Lzma::Filter;
#package Lzma::Filter::Lzma;

#our ($VERSION, @ISA, @EXPORT, $AUTOLOAD);
@Lzma::Filter::Lzma::ISA = qw(Lzma::Filter);

sub Lzma::Filter::Lzma::mk
{
    my $type = shift;

    my $got = Compress::Raw::Lzma::ParseParameters(0,
        {
            'DictSize' =&gt; [1, 1, Parse_unsigned(), LZMA_DICT_SIZE_DEFAULT()],
            #'PreserDict' =&gt; [1, 1, Parse_unsigned(), undef],
            'Lc'    =&gt; [1, 1, Parse_unsigned(), LZMA_LC_DEFAULT()],
            'Lp'    =&gt; [1, 1, Parse_unsigned(), LZMA_LP_DEFAULT()],
            'Pb'    =&gt; [1, 1, Parse_unsigned(), LZMA_PB_DEFAULT()],
            'Mode'  =&gt; [1, 1, Parse_unsigned(), LZMA_MODE_NORMAL()],
            'Nice'  =&gt; [1, 1, Parse_unsigned(), 64],
            'Mf'    =&gt; [1, 1, Parse_unsigned(), LZMA_MF_BT4()],
            'Depth' =&gt; [1, 1, Parse_unsigned(), 0],
        }, @_) ;

    my $pkg = (caller(1))[3] ;

    my $DictSize = $got-&gt;value('DictSize');
    die "Dictsize $DictSize not in range 4KiB - 1536Mib"
        if $DictSize &lt; 1024 * 4 || 
           $DictSize &gt; 1024 * 1024 * 1536 ;

    my $Lc = $got-&gt;value('Lc');
    die "Lc $Lc not in range 0-4"
        if $Lc &lt; 0 || $Lc &gt; 4;

    my $Lp = $got-&gt;value('Lp');
    die "Lp $Lp not in range 0-4"
        if $Lp &lt; 0 || $Lp &gt; 4;

    die "Lc + Lp must be &lt;= 4"
        if $Lc + $Lp &gt; 4;

    my $Pb = $got-&gt;value('Pb');
    die "Pb $Pb not in range 0-4"
        if $Pb &lt; 0 || $Pb &gt; 4;

    my $Mode = $got-&gt;value('Mode');
    die "Mode $Mode not LZMA_MODE_FAST or LZMA_MODE_NORMAL"
        if $Mode != LZMA_MODE_FAST() &amp;&amp; $Mode != LZMA_MODE_NORMAL();

    my $Mf = $got-&gt;value('Mf');
    die "Mf $Mf not valid"
        if ! grep { $Mf == $_ } 
             ( LZMA_MF_HC3(),
               LZMA_MF_HC4(),
               LZMA_MF_BT2(),
               LZMA_MF_BT3(),
               LZMA_MF_BT4());

    my $Nice = $got-&gt;value('Nice');
    die "Nice $Nice not in range 2-273"
        if $Nice &lt; 2 || $Nice &gt; 273;

    my $obj = Lzma::Filter::Lzma::_mk($type, 
                            $DictSize,
                            $Lc,
                            $Lp,
                            $Pb,
                            $Mode,
                            $Nice,
                            $Mf,
                            $got-&gt;value('Depth'),
                        );    

    bless $obj, $pkg
        if defined $obj;

    $obj;    
}

sub Lzma::Filter::Lzma::mkPreset
{
    my $type = shift;

    my $preset = shift;
    my $pkg = (caller(1))[3] ;

    my $obj = Lzma::Filter::Lzma::_mkPreset($type, $preset);    

    bless $obj, $pkg
        if defined $obj;

    $obj;    
}

@Lzma::Filter::Lzma1::ISA = qw(Lzma::Filter::Lzma);
sub Lzma::Filter::Lzma1
{
    Lzma::Filter::Lzma::mk(0, @_);    
}

@Lzma::Filter::Lzma1::Preset::ISA = qw(Lzma::Filter::Lzma);
sub Lzma::Filter::Lzma1::Preset
{
    Lzma::Filter::Lzma::mkPreset(0, @_);    
}


@Lzma::Filter::Lzma2::ISA = qw(Lzma::Filter::Lzma);
sub Lzma::Filter::Lzma2
{
    Lzma::Filter::Lzma::mk(1, @_);    
}

@Lzma::Filter::Lzma2::Preset::ISA = qw(Lzma::Filter::Lzma);
sub Lzma::Filter::Lzma2::Preset
{
    Lzma::Filter::Lzma::mkPreset(1, @_);    
}

@Lzma::Filter::BCJ::ISA = qw(Lzma::Filter);

sub Lzma::Filter::BCJ::mk
{
    my $type = shift;
    my $got = Compress::Raw::Lzma::ParseParameters(0,
            {
                'Offset' =&gt; [1, 1, Parse_unsigned(), 0],
            }, @_) ;

    my $pkg = (caller(1))[3] ;
    my $obj = Lzma::Filter::BCJ::_mk($type, $got-&gt;value('Offset')) ;
    bless $obj, $pkg
        if defined $obj;

    $obj;    
}

@Lzma::Filter::X86::ISA = qw(Lzma::Filter::BCJ);

sub Lzma::Filter::X86
{
    Lzma::Filter::BCJ::mk(LZMA_FILTER_X86(), @_);    
}

@Lzma::Filter::PowerPC::ISA = qw(Lzma::Filter::BCJ);

sub Lzma::Filter::PowerPC
{
    Lzma::Filter::BCJ::mk(LZMA_FILTER_POWERPC(), @_);    
}

@Lzma::Filter::IA64::ISA = qw(Lzma::Filter::BCJ);

sub Lzma::Filter::IA64
{
    Lzma::Filter::BCJ::mk(LZMA_FILTER_IA64(), @_);    
}

@Lzma::Filter::ARM::ISA = qw(Lzma::Filter::BCJ);

sub Lzma::Filter::ARM
{
    Lzma::Filter::BCJ::mk(LZMA_FILTER_ARM(), @_);    
}

@Lzma::Filter::ARMThumb::ISA = qw(Lzma::Filter::BCJ);

sub Lzma::Filter::ARMThumb
{
    Lzma::Filter::BCJ::mk(LZMA_FILTER_ARMTHUMB(), @_);    
}

@Lzma::Filter::Sparc::ISA = qw(Lzma::Filter::BCJ);

sub Lzma::Filter::Sparc
{
    Lzma::Filter::BCJ::mk(LZMA_FILTER_SPARC(), @_);    
}


@Lzma::Filter::Delta::ISA = qw(Lzma::Filter);
sub Lzma::Filter::Delta
{
    #my $pkg = shift ;
    my ($got) = Compress::Raw::Lzma::ParseParameters(0,
            {
                'Type'   =&gt; [1, 1, Parse_unsigned,  LZMA_DELTA_TYPE_BYTE()],
                'Distance' =&gt; [1, 1, Parse_unsigned, LZMA_DELTA_DIST_MIN()],
            }, @_) ;

    Lzma::Filter::Delta::_mk($got-&gt;value('Type'),
                             $got-&gt;value('Distance')) ;
}

#package Lzma::Filter::SubBlock;


package Compress::Raw::Lzma;

1;

__END__


=head1 NAME

Compress::Raw::Lzma - Low-Level Interface to lzma compression library

=head1 SYNOPSIS

    use Compress::Raw::Lzma ;

    # Encoders
    my ($lz, $status) = new Compress::Raw::Lzma::EasyEncoder [OPTS]
        or die "Cannot create lzma object: $status\n";
    
    my ($lz, $status) = new Compress::Raw::Lzma::AloneEncoder [OPTS]
        or die "Cannot create lzma object: $status\n";
    
    my ($lz, $status) = new Compress::Raw::Lzma::StreamEncoder [OPTS]
        or die "Cannot create lzma object: $status\n";
    
    my ($lz, $status) = new Compress::Raw::Lzma::RawEncoder [OPTS]
        or die "Cannot create lzma object: $status\n";
    
    $status = $lz-&gt;code($input, $output);
    $status = $lz-&gt;flush($output);

    # Decoders
    my ($lz, $status) = new Compress::Raw::Lzma::AloneDecoder [OPTS]
        or die "Cannot create bunzip2 object: $status\n";
    
    my ($lz, $status) = new Compress::Raw::Lzma::AutoDecoder [OPTS]
        or die "Cannot create bunzip2 object: $status\n";
    
    my ($lz, $status) = new Compress::Raw::Lzma::StreamDecoder [OPTS]
        or die "Cannot create bunzip2 object: $status\n";
    
    my ($lz, $status) = new Compress::Raw::Lzma::RawDecoder [OPTS]
        or die "Cannot create bunzip2 object: $status\n";
    
    $status = $lz-&gt;code($input, $output);

    my $version = Compress::Raw::Lzma::lzma_version_number();
    my $version = Compress::Raw::Lzma::lzma_version_string();

=head1 DESCRIPTION

C&lt;Compress::Raw::Lzma&gt; provides an interface to the in-memory
compression/uncompression functions from the lzma compression library. 

Although the primary purpose for the existence of C&lt;Compress::Raw::Lzma&gt; is
for use by the  C&lt;IO::Compress::Lzma&gt;, C&lt;IO::Uncompress::UnLzma&gt;,
C&lt;IO::Compress::Xz&gt; and C&lt;IO::Uncompress::UnXz&gt; modules, it can be used on
its own for simple compression/uncompression tasks.

=head1 Compression

There are four compression interfaces available in this module.

=over 5

=item Compress::Raw::Lzma::EasyEncoder
=item Compress::Raw::Lzma::AloneEncoder
=item Compress::Raw::Lzma::StreamEncoder
=item Compress::Raw::Lzma::RawEncoder

=back

=head2 ($z, $status) = new Compress::Raw::Lzma::EasyEncoder [OPTS];

Creates a new I&lt;xz&gt; compression object. 

If successful, it will return the initialised compression object, C&lt;$z&gt;
and a C&lt;$status&gt; of C&lt;LZMA_OK&gt; in a list context. In scalar context it
returns the deflation object, C&lt;$z&gt;, only.

If not successful, the returned compression object, C&lt;$z&gt;, will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the an I&lt;lzma&gt; error code.

Below is a list of the valid options:

=over 5

=item B&lt;&lt; Preset =&gt; $preset &gt;&gt;

Used to choose the compression preset.

Valid values are 0-9 and C&lt;LZMA_PRESET_DEFAULT&gt;.

0 is the fastest compression with the lowest memory usage and the lowest
compression.

9 is the slowest compression with the highest memory usage but with the best
compression.

Defaults to C&lt;LZMA_PRESET_DEFAULT&gt;.

=item B&lt;&lt; Extreme =&gt; 0|1 &gt;&gt;

Makes the compression a lot slower, but a small compression gain.

Defaults to 0.

=item B&lt;&lt; Check =&gt; $check &gt;&gt;

Used to specify the integrity check used in the xz data stream.
Valid values are C&lt;LZMA_CHECK_NONE&gt;, C&lt;LZMA_CHECK_CRC32&gt;,
C&lt;LZMA_CHECK_CRC64&gt;, C&lt;LZMA_CHECK_SHA256&gt;.

Defaults to C&lt;LZMA_CHECK_CRC32&gt;.

=item B&lt;&lt; AppendOutput =&gt; 0|1 &gt;&gt;

Controls whether the compressed data is appended to the output buffer in
the C&lt;code&gt; and C&lt;flush&gt; methods.

Defaults to 1.

=item B&lt;&lt; BufSize =&gt; $number &gt;&gt;

Sets the initial size for the output buffer used by the C&lt;$d-E&lt;gt&gt;code&gt;
method. If the buffer has to be reallocated to increase the size, it will
grow in increments of C&lt;Bufsize&gt;.

Defaults to 16k.

=back

=head2 ($z, $status) = new Compress::Raw::Lzma::AloneEncoder [OPTS];

Creates a legacy I&lt;lzma&gt; compression object. This format is also know as
lzma_alone.

If successful, it will return the initialised compression object, C&lt;$z&gt;
and a C&lt;$status&gt; of C&lt;LZMA_OK&gt; in a list context. In scalar context it
returns the deflation object, C&lt;$z&gt;, only.

If not successful, the returned compression object, C&lt;$z&gt;, will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the an I&lt;lzma&gt; error code.

Below is a list of the valid options:

=over 5

=item B&lt;&lt; Filter =&gt; $filter &gt;&gt;

The C&lt; $filter &gt; option must be an object of type C&lt;Lzma::Filter::Lzma1&gt;.
See L&lt;Compress::Raw::Lzma/Lzma::Filter::Lzma&gt; for a definition 
of C&lt;Lzma::Filter::Lzma1&gt;.

If this option is not present an C&lt;Lzma::Filter::Lzma1&gt; object with default
values will be used.

=item B&lt;&lt; AppendOutput =&gt; 0|1 &gt;&gt;

Controls whether the compressed data is appended to the output buffer in
the C&lt;code&gt; and C&lt;flush&gt; methods.

Defaults to 1.

=item B&lt;&lt; BufSize =&gt; $number &gt;&gt;

Sets the initial size for the output buffer used by the C&lt;$d-E&lt;gt&gt;code&gt;
method. If the buffer has to be reallocated to increase the size, it will
grow in increments of C&lt;Bufsize&gt;.

Defaults to 16k.

=back

=head2 ($z, $status) = new Compress::Raw::Lzma::StreamEncoder [OPTS];

Creates a I&lt;xz&gt; compression object. 

If successful, it will return the initialised compression object, C&lt;$z&gt;
and a C&lt;$status&gt; of C&lt;LZMA_OK&gt; in a list context. In scalar context it
returns the deflation object, C&lt;$z&gt;, only.

If not successful, the returned compression object, C&lt;$z&gt;, will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the an I&lt;lzma&gt; error code.

Below is a list of the valid options:

=over 5

=item B&lt;&lt; Filter =&gt; $filter &gt;&gt;
=item B&lt;&lt; Filter =&gt; [$filter1, $filter2,...] &gt;&gt;

This option is used to change the bahaviour of the StreamEncoder by
applying between one and C&lt;LZMA_FILTERS_MAX&gt; filters to the data stream
during compression. See L&lt;/Filters&gt; for more details on the available
filters.

If this option is present it must either contain a single
C&lt;Lzma::Filter::Lzma&gt; filter object or an array reference containing between 
one and C&lt;LZMA_FILTERS_MAX&gt; filter objects.

If this option is not present an C&lt;Lzma::Filter::Lzma2&gt; object with default
values will be used.

=item B&lt;&lt; Check =&gt; $check &gt;&gt;

Used to specify the integrity check used in the xz data stream.
Valid values are C&lt;LZMA_CHECK_NONE&gt;, C&lt;LZMA_CHECK_CRC32&gt;,
C&lt;LZMA_CHECK_CRC64&gt;, C&lt;LZMA_CHECK_SHA256&gt;.

Defaults to C&lt;LZMA_CHECK_CRC32&gt;.

=item B&lt;&lt; AppendOutput =&gt; 0|1 &gt;&gt;

Controls whether the compressed data is appended to the output buffer in
the C&lt;code&gt; and C&lt;flush&gt; methods.

Defaults to 1.

=item B&lt;&lt; BufSize =&gt; $number &gt;&gt;

Sets the initial size for the output buffer used by the C&lt;$d-E&lt;gt&gt;code&gt;
method. If the buffer has to be reallocated to increase the size, it will
grow in increments of C&lt;Bufsize&gt;.

Defaults to 16k.

=back

=head2 ($z, $status) = new Compress::Raw::Lzma::RawEncoder [OPTS];

Low level access to lzma.

If successful, it will return the initialised compression object, C&lt;$z&gt;
and a C&lt;$status&gt; of C&lt;LZMA_OK&gt; in a list context. In scalar context it
returns the deflation object, C&lt;$z&gt;, only.

If not successful, the returned compression object, C&lt;$z&gt;, will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the an I&lt;lzma&gt; error code.

Below is a list of the valid options:

=over 5

=item B&lt;&lt; Filter =&gt; $filter &gt;&gt;
=item B&lt;&lt; Filter =&gt; [$filter1, $filter2,...] &gt;&gt;

This option is used to change the bahaviour of the RawEncoder by
applying between one and C&lt;LZMA_FILTERS_MAX&gt; filters to the data stream
during compression. See L&lt;/Filters&gt; for more details on the available
filters.

If this option is present it must either contain a single
C&lt;Lzma::Filter::Lzma&gt; filter object or an array reference containing between 
one and C&lt;LZMA_FILTERS_MAX&gt; filter objects.

If this option is not present an C&lt;Lzma::Filter::Lzma2&gt; object with default
values will be used.

=item B&lt;&lt; AppendOutput =&gt; 0|1 &gt;&gt;

Controls whether the compressed data is appended to the output buffer in
the C&lt;code&gt; and C&lt;flush&gt; methods.

Defaults to 1.

=item B&lt;&lt; BufSize =&gt; $number &gt;&gt;

Sets the initial size for the output buffer used by the C&lt;$d-E&lt;gt&gt;code&gt;
method. If the buffer has to be reallocated to increase the size, it will
grow in increments of C&lt;Bufsize&gt;.

Defaults to 16k.

=item B&lt;&lt; ForZip =&gt; 1/0 &gt;&gt;

This boolean option is used to enable prefixing the compressed data stream
with an encoded copy of the filter properties.

Defaults to 0.

=back

=head2 $status = $lz-&gt;code($input, $output);

Reads the contents of C&lt;$input&gt;, compresses it and writes the compressed
data to C&lt;$output&gt;.

Returns C&lt;LZMA_OK&gt; on success and an C&lt;lzma&gt; error code on failure.

If C&lt;appendOutput&gt; is enabled in the constructor for the lzma object, the
compressed data will be appended to C&lt;$output&gt;. If not enabled, C&lt;$output&gt;
will be truncated before the compressed data is written to it.

=head2 $status = $lz-&gt;flush($output, LZMA_FINISH);

Flushes any pending compressed data to C&lt;$output&gt;. By default it terminates
the compressed data stream.

Returns C&lt;LZMA_OK&gt; on success and an C&lt;lzma&gt; error code on failure.

=head2 Example

TODO

=head1 Uncompression

There are four uncompression interfaces available in this module.

=over 5

=item Compress::Raw::Lzma::AutoDecoder
=item Compress::Raw::Lzma::AloneDecoder
=item Compress::Raw::Lzma::StreamDecoder
=item Compress::Raw::Lzma::RawDecoder

=back

=head2 ($z, $status) = new Compress::Raw::Lzma::AutoDecoder [OPTS] ;

Create an object that can uncompress any of the compressed data streams
that can be created by this module.

If successful, it will return the initialised uncompression object, C&lt;$z&gt;
and a C&lt;$status&gt; of C&lt;LZMA_OK&gt; in a list context. In scalar context it
returns the deflation object, C&lt;$z&gt;, only.

If not successful, the returned uncompression object, C&lt;$z&gt;, will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the an I&lt;lzma&gt; error code.

Below is a list of the valid options:

=over 5

=item B&lt;-MemLimit&gt;

The number of bytes to use when uncompressing.

Default is unlimited.

=item B&lt;-Bufsize&gt;

Sets the initial size for the output buffer used by the C&lt;$i-E&lt;gt&gt;code&gt;
method. If the output buffer in this method has to be reallocated to
increase the size, it will grow in increments of C&lt;Bufsize&gt;.

Default is 16k.

=item B&lt;-AppendOutput&gt;

This option controls how data is written to the output buffer by the
C&lt;$i-E&lt;gt&gt;code&gt; method.

If the option is set to false, the output buffer in the C&lt;$i-E&lt;gt&gt;code&gt;
method will be truncated before uncompressed data is written to it.

If the option is set to true, uncompressed data will be appended to the
output buffer by the C&lt;$i-E&lt;gt&gt;code&gt; method.

This option defaults to false.

=item B&lt;-ConsumeInput&gt;

If set to true, this option will remove compressed data from the input
buffer of the C&lt;&lt; $i-&gt;code &gt;&gt; method as the uncompression progresses.

This option can be useful when you are processing compressed data that is
embedded in another file/buffer. In this case the data that immediately
follows the compressed stream will be left in the input buffer.

This option defaults to true.

=item B&lt;-LimitOutput&gt;

The C&lt;LimitOutput&gt; option changes the behavior of the C&lt;&lt; $i-&gt;code &gt;&gt;
method so that the amount of memory used by the output buffer can be
limited. 

When C&lt;LimitOutput&gt; is used the size of the output buffer used will either
be the value of the C&lt;Bufsize&gt; option or the amount of memory already
allocated to C&lt;$output&gt;, whichever is larger. Predicting the output size
available is tricky, so don't rely on getting an exact output buffer size.

When C&lt;LimitOutout&gt; is not specified C&lt;&lt; $i-&gt;code &gt;&gt; will use as much
memory as it takes to write all the uncompressed data it creates by
uncompressing the input buffer.

If C&lt;LimitOutput&gt; is enabled, the C&lt;ConsumeInput&gt; option will also be
enabled.

This option defaults to false.

See L&lt;/The LimitOutput option&gt; for a discussion on why C&lt;LimitOutput&gt; is
needed and how to use it.

=back

=head2 ($z, $status) = new Compress::Raw::Lzma::AloneDecoder [OPTS] ;

Create an object that can uncompress an lzma_alone data stream.

If successful, it will return the initialised uncompression object, C&lt;$z&gt;
and a C&lt;$status&gt; of C&lt;LZMA_OK&gt; in a list context. In scalar context it
returns the deflation object, C&lt;$z&gt;, only.

If not successful, the returned uncompression object, C&lt;$z&gt;, will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the an I&lt;lzma&gt; error code.

Below is a list of the valid options:

=over 5

=item B&lt;-MemLimit&gt;

The number of bytes to use when uncompressing.

Default is unlimited.

=item B&lt;-Bufsize&gt;

Sets the initial size for the output buffer used by the C&lt;$i-E&lt;gt&gt;code&gt;
method. If the output buffer in this method has to be reallocated to
increase the size, it will grow in increments of C&lt;Bufsize&gt;.

Default is 16k.

=item B&lt;-AppendOutput&gt;

This option controls how data is written to the output buffer by the
C&lt;$i-E&lt;gt&gt;code&gt; method.

If the option is set to false, the output buffer in the C&lt;$i-E&lt;gt&gt;code&gt;
method will be truncated before uncompressed data is written to it.

If the option is set to true, uncompressed data will be appended to the
output buffer by the C&lt;$i-E&lt;gt&gt;code&gt; method.

This option defaults to false.

=item B&lt;-ConsumeInput&gt;

If set to true, this option will remove compressed data from the input
buffer of the C&lt;&lt; $i-&gt;code &gt;&gt; method as the uncompression progresses.

This option can be useful when you are processing compressed data that is
embedded in another file/buffer. In this case the data that immediately
follows the compressed stream will be left in the input buffer.

This option defaults to true.

=item B&lt;-LimitOutput&gt;

The C&lt;LimitOutput&gt; option changes the behavior of the C&lt;&lt; $i-&gt;code &gt;&gt;
method so that the amount of memory used by the output buffer can be
limited. 

When C&lt;LimitOutput&gt; is used the size of the output buffer used will either
be the value of the C&lt;Bufsize&gt; option or the amount of memory already
allocated to C&lt;$output&gt;, whichever is larger. Predicting the output size
available is tricky, so don't rely on getting an exact output buffer size.

When C&lt;LimitOutout&gt; is not specified C&lt;&lt; $i-&gt;code &gt;&gt; will use as much
memory as it takes to write all the uncompressed data it creates by
uncompressing the input buffer.

If C&lt;LimitOutput&gt; is enabled, the C&lt;ConsumeInput&gt; option will also be
enabled.

This option defaults to false.

See L&lt;/The LimitOutput option&gt; for a discussion on why C&lt;LimitOutput&gt; is
needed and how to use it.

=back

=head2 $status = $z-&gt;code($input, $output);

Uncompresses C&lt;$input&gt; and writes the uncompressed data to C&lt;$output&gt;. 

Returns C&lt;LZMA_OK&gt; if the uncompression was successful, but the end of the
compressed data stream has not been reached. Returns C&lt;LZMA_STREAM_END&gt; on
successful uncompression and the end of the compression stream has been
reached.

If C&lt;consumeInput&gt; is enabled in the constructor for the lzma object,
C&lt;$input&gt; will have all compressed data removed from it after
uncompression. On C&lt;LZMA_OK&gt; return this will mean that C&lt;$input&gt; will be an
empty string; when C&lt;LZMA_STREAM_END&gt; C&lt;$input&gt; will either be an empty
string or will contain whatever data immediately followed the compressed
data stream.

If C&lt;appendOutput&gt; is enabled in the constructor for the lzma object,
the uncompressed data will be appended to C&lt;$output&gt;. If not enabled,
C&lt;$output&gt; will be truncated before the uncompressed data is written to it.

=head1 Filters

TODO - more here

A number of the Lzma compression interfaces (namely
C&lt;Compress::Raw::Lzma::StreamEncoder&gt; &amp;
C&lt;Compress::Raw::Lzma::AloneEncoder&gt;) and the raw lzma uncompression interface
make use of filters. These filters are used to change the behaviour of
compression (and raw uncompression).

All Lzma Filters are sub-classed from the C&lt;Lzma::Filter&gt; base-class.

=head2 Lzma::Filter::Lzma

The C&lt;Lzma::Filter::Lzma&gt; class is used to... TODO - more here

There are two subclasses of C&lt;Lzma::Filter::Lzma&gt;, namely
C&lt;Lzma::Filter::Lzma1&gt; and C&lt;Lzma::Filter::Lzma2&gt;. 

The former is typically used with C&lt;Compress::Raw::Lzma::AloneEncoder&gt;.
The latter with C&lt;Compress::Raw::Lzma::StreamEncoder&gt;.

When using Lzma filters an C&lt;Lzma::Filter::Lzma&gt; I&lt;must&gt; be included and it
I&lt;must&gt; be the last filter in the chain. There can only be one
C&lt;Lzma::Filter::Lzma&gt; filter in any filter chain.

The C&lt;Lzma::Filter::Lzma&gt; construction takes the following options.

=over 5

=item DictSize =&gt; $value

Dictionary size in bytes. This controls 
how many bytes of the recently processed
uncompressed data is kept in memory. The size of the dictionary must be at
least C&lt;LZMA_DICT_SIZE_MIN&gt;.

Defaults to C&lt;LZMA_DICT_SIZE_DEFAULT&gt;.

=item Lc =&gt; $value

Number of literal context bits.

How many of the highest bits of the previous uncompressed
eight-bit byte (also known as `literal') are taken into
account when predicting the bits of the next literal.

C&lt;$value&gt; must be a number between C&lt;LZMA_LCLP_MIN&gt; and
C&lt;LZMA_LCLP_MAX&gt;.
	 
Note the sum of the C&lt;Lc&gt; and C&lt;Lp&gt; options cannot exceed 4.

Defaults to C&lt;LZMA_LC_DEFAULT&gt;.

=item Lp =&gt; $value

Number of literal position bits.

How many of the lowest bits of the current position (number
of bytes from the beginning of the uncompressed data) in the
uncompressed data is taken into account when predicting the
bits of the next literal (a single eight-bit byte).

Defaults to C&lt;LZMA_LP_DEFAULT&gt;.

=item Pb =&gt; $value

Number of position bits

How many of the lowest bits of the current position in the
uncompressed data is taken into account when estimating
probabilities of matches. A match is a sequence of bytes for
which a matching sequence is found from the dictionary and
thus can be stored as distance-length pair.

C&lt;$value&gt; must be a number between C&lt;LZMA_PB_MIN&gt; and
C&lt;LZMA_PB_MAX&gt;.

Defaults to C&lt;LZMA_PB_DEFAULT&gt;.

=item Mode =&gt; $value

The Compression Mode. Valid values are C&lt;LZMA_MODE_FAST&gt; and
C&lt;LZMA_MODE_NORMAL&gt;.

Defaults to C&lt;LZMA_MODE_NORMAL&gt;.

=item Nice =&gt; $value

Nice length of a match

Defaults to 64.

=item Mf =&gt; $value

Defines which Match Finder to use. Valid values are C&lt;LZMA_MF_HC3&gt;
C&lt;LZMA_MF_HC4&gt;, C&lt;LZMA_MF_BT2&gt; C&lt;LZMA_MF_BT3&gt; and C&lt;LZMA_MF_BT4&gt;.

Defaults to C&lt;LZMA_MF_BT4&gt;.

=item Depth =&gt; $value

Maximum search depth in the match finder.

Defaults to 0.

=back

=head2 Lzma::Filter::BCJ

The sub-classes of C&lt;Lzma::Filter::BCJ&gt; are the
Branch/Call/Jump conversion filters. These filters are used to rewrite
executable binary code for a number of processor architectures. 
None of these classes take any options.

=over 5

=item Lzma::Filter::X86

Filter for x86 binaries.

=item Lzma::Filter::PowerPC

Filter for Big endian PowerPC binaries.

=item Lzma::Filter::IA64

Filter for IA64 (Itanium) binaries.

=item Lzma::Filter::ARM

Filter for ARM binaries.

=item Lzma::Filter::ARMThumb

Filter for ARMThumb binaries.

=item Lzma::Filter::Sparc

Filter for Sparc binaries.

=back

=head2 Lzma::Filter::Delta

Usage is

    Lzma::Filter::Delta [OPTS]

=over 5

=item Type =&gt; $type

Defines the type of Delta calculation. The only available type (and
therefore the default) is
C&lt;LZMA_DELTA_TYPE_BYTE&gt;,

=item Distance =&gt; $value

Defines the Delta Distance. C&lt;$value&gt; must be a number between
C&lt;LZMA_DELTA_DIST_MIN&gt; and C&lt;LZMA_DELTA_DIST_MAX&gt;.

Default is C&lt;LZMA_DELTA_DIST_MIN&gt;.

=back

=head1 Misc

=head2 my $version = Compress::Raw::Lzma::lzma_version_number();

Returns the version of the underlying lzma library.

=head2 my $version = Compress::Raw::Lzma::lzma_version_string();

Returns the version of the underlying lzma library.

TODO - more here

=head1 Constants

The following lzma constants are exported by this module

TODO - more here

=head1 SEE ALSO

L&lt;Compress::Zlib&gt;, L&lt;IO::Compress::Gzip&gt;, L&lt;IO::Uncompress::Gunzip&gt;, L&lt;IO::Compress::Deflate&gt;, L&lt;IO::Uncompress::Inflate&gt;, L&lt;IO::Compress::RawDeflate&gt;, L&lt;IO::Uncompress::RawInflate&gt;, L&lt;IO::Compress::Bzip2&gt;, L&lt;IO::Uncompress::Bunzip2&gt;, L&lt;IO::Compress::Lzma&gt;, L&lt;IO::Uncompress::UnLzma&gt;, L&lt;IO::Compress::Xz&gt;, L&lt;IO::Uncompress::UnXz&gt;, L&lt;IO::Compress::Lzop&gt;, L&lt;IO::Uncompress::UnLzop&gt;, L&lt;IO::Compress::Lzf&gt;, L&lt;IO::Uncompress::UnLzf&gt;, L&lt;IO::Uncompress::AnyInflate&gt;, L&lt;IO::Uncompress::AnyUncompress&gt;

L&lt;IO::Compress::FAQ|IO::Compress::FAQ&gt;

L&lt;File::GlobMapper|File::GlobMapper&gt;, L&lt;Archive::Zip|Archive::Zip&gt;,
L&lt;Archive::Tar|Archive::Tar&gt;,
L&lt;IO::Zlib|IO::Zlib&gt;

=head1 AUTHOR

This module was written by Paul Marquess, F&lt;pmqs@cpan.org&gt;. 

=head1 MODIFICATION HISTORY

See the Changes file.

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2005-2013 Paul Marquess. All rights reserved.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

</pre></body></html>