File Coverage

blib/lib/IO/Compress/Adapter/Xz.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package IO::Compress::Adapter::Xz ;
2              
3 13     13   47 use strict;
  13         17  
  13         348  
4 13     13   44 use warnings;
  13         14  
  13         269  
5 13     13   42 use bytes;
  13         15  
  13         63  
6              
7 13     13   272 use IO::Compress::Base::Common 2.073 qw(:Status);
  13         171  
  13         1666  
8              
9 13     13   8952 use Compress::Raw::Lzma 2.073 qw(LZMA_OK LZMA_STREAM_END LZMA_PRESET_DEFAULT LZMA_CHECK_CRC32) ;
  0            
  0            
10              
11             our ($VERSION);
12             $VERSION = '2.073';
13              
14             sub mkCompObject
15             {
16             my $Preset = shift ;
17             my $Extreme = shift ;
18             my $Check = shift ;
19              
20             my ($def, $status) = Compress::Raw::Lzma::EasyEncoder->new(AppendOutput => 1,
21             Preset => $Preset,
22             Extreme => $Extreme,
23             Check => $Check);
24              
25             return (undef, "Could not create EasyEncoder object: $status", $status)
26             if $status != LZMA_OK ;
27              
28             return bless {'Def' => $def,
29             'Error' => '',
30             'ErrorNo' => 0,
31             } ;
32             }
33              
34             sub compr
35             {
36             my $self = shift ;
37              
38             my $def = $self->{Def};
39              
40             my $status = $def->code($_[0], $_[1]) ;
41             $self->{ErrorNo} = $status;
42              
43             if ($status != LZMA_OK)
44             {
45             $self->{Error} = "Deflate Error: $status";
46             return STATUS_ERROR;
47             }
48              
49             #${ $_[1] } .= $out if defined $out;
50              
51             return STATUS_OK;
52             }
53              
54             sub flush
55             {
56             my $self = shift ;
57              
58             my $def = $self->{Def};
59              
60             my $status = $def->flush($_[0]);
61             $self->{ErrorNo} = $status;
62              
63             if ($status != LZMA_STREAM_END)
64             {
65             $self->{Error} = "Deflate Error: $status";
66             return STATUS_ERROR;
67             }
68              
69             #${ $_[0] } .= $out if defined $out ;
70             return STATUS_OK;
71            
72             }
73              
74             sub close
75             {
76             my $self = shift ;
77              
78             my $def = $self->{Def};
79              
80             my $status = $def->flush($_[0]);
81             $self->{ErrorNo} = $status;
82              
83             if ($status != LZMA_STREAM_END)
84             {
85             $self->{Error} = "Deflate Error: $status";
86             return STATUS_ERROR;
87             }
88              
89             #${ $_[0] } .= $out if defined $out ;
90             return STATUS_OK;
91            
92             }
93              
94              
95             sub reset
96             {
97             my $self = shift ;
98              
99             my $outer = $self->{Outer};
100              
101             my ($def, $status) = Compress::Raw::Lzma->lzma_easy_encoder();
102             $self->{ErrorNo} = ($status == LZMA_OK) ? 0 : $status ;
103              
104             if ($status != LZMA_OK)
105             {
106             $self->{Error} = "Cannot create Deflate object: $status";
107             return STATUS_ERROR;
108             }
109              
110             $self->{Def} = $def;
111              
112             return STATUS_OK;
113             }
114              
115             sub compressedBytes
116             {
117             my $self = shift ;
118             $self->{Def}->compressedBytes();
119             }
120              
121             sub uncompressedBytes
122             {
123             my $self = shift ;
124             $self->{Def}->uncompressedBytes();
125             }
126              
127             #sub total_out
128             #{
129             # my $self = shift ;
130             # 0;
131             #}
132             #
133              
134             #sub total_in
135             #{
136             # my $self = shift ;
137             # $self->{Def}->total_in();
138             #}
139             #
140             #sub crc32
141             #{
142             # my $self = shift ;
143             # $self->{Def}->crc32();
144             #}
145             #
146             #sub adler32
147             #{
148             # my $self = shift ;
149             # $self->{Def}->adler32();
150             #}
151              
152              
153             1;
154              
155             __END__