summaryrefslogtreecommitdiff
path: root/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm
blob: 0df174320a7cf0050facda2c4685019728c35ab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package IO::Uncompress::Adapter::Identity;

use warnings;
use strict;
use bytes;

use IO::Compress::Base::Common  2.021 qw(:Status);

our ($VERSION);

$VERSION = '2.021';

use Compress::Raw::Zlib  2.021 ();

sub mkUncompObject
{
    my $crc32 = 1; #shift ;
    my $adler32 = shift;

    bless { 'CompSize'   => 0,
            'UnCompSize' => 0,
            'wantCRC32'  => $crc32,
            'CRC32'      => Compress::Raw::Zlib::crc32(''),
            'wantADLER32'=> $adler32,
            'ADLER32'    => Compress::Raw::Zlib::adler32(''),
            'ConsumesInput' => 1,

          } ;
}

sub uncompr
{
    my $self = shift;
    my $eof = $_[2];

    if (defined ${ $_[0] } && length ${ $_[0] }) {
        $self->{CompSize} += length ${ $_[0] } ;
        $self->{UnCompSize} = $self->{CompSize} ;

        $self->{CRC32} = Compress::Raw::Zlib::crc32($_[0],  $self->{CRC32})
            if $self->{wantCRC32};

        $self->{ADLER32} = Compress::Zlib::adler32($_[0],  $self->{ADLER32})
            if $self->{wantADLER32};

        ${ $_[1] } .= ${ $_[0] };
        ${ $_[0] } = "";
    }

    return STATUS_ENDSTREAM if $eof;
    return STATUS_OK ;
}

sub reset
{
    my $self = shift;

    $self->{CompSize}   = 0;
    $self->{UnCompSize} = 0;
    $self->{CRC32}      = Compress::Raw::Zlib::crc32('');
    $self->{ADLER32}    = Compress::Raw::Zlib::adler32('');      

    return STATUS_OK ;
}


#sub count
#{
#    my $self = shift ;
#    return $self->{UnCompSize} ;
#}

sub compressedBytes
{
    my $self = shift ;
    return $self->{UnCompSize} ;
}

sub uncompressedBytes
{
    my $self = shift ;
    return $self->{UnCompSize} ;
}

sub sync
{
    return STATUS_OK ;
}

sub crc32
{
    my $self = shift ;
    return $self->{CRC32};
}

sub adler32
{
    my $self = shift ;
    return $self->{ADLER32};
}


1;

__END__