line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::SPDY::Compress; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Protocol::SPDY::Compress::VERSION = '1.000'; |
4
|
|
|
|
|
|
|
} |
5
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
125
|
|
6
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
115
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Protocol::SPDY::Compress - handle zlib compression/decompression |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 1.000 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Protocol::SPDY; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Used internally. See L instead. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
3
|
|
252502
|
use Compress::Raw::Zlib qw(Z_OK Z_SYNC_FLUSH WANT_GZIP_OR_ZLIB); |
|
3
|
|
|
|
|
23420
|
|
|
3
|
|
|
|
|
485
|
|
27
|
3
|
|
|
3
|
|
27
|
use Protocol::SPDY::Constants ':all'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2136
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Instantiate - takes no parameters. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
14
|
|
|
14
|
1
|
2978
|
sub new { my $class = shift; bless { }, $class } |
|
14
|
|
|
|
|
110
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 inflater |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns an inflater object, for decompressing data. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub inflater { |
48
|
20
|
|
|
20
|
1
|
27
|
my $self = shift; |
49
|
20
|
100
|
|
|
|
77
|
return $self->{inflater} if $self->{inflater}; |
50
|
8
|
|
|
|
|
14728
|
my ($d, $status) = Compress::Raw::Zlib::Inflate->new( |
51
|
|
|
|
|
|
|
-WindowBits => WANT_GZIP_OR_ZLIB, |
52
|
|
|
|
|
|
|
-Dictionary => ZLIB_DICTIONARY, |
53
|
|
|
|
|
|
|
); |
54
|
8
|
50
|
|
|
|
3003
|
die "Zlib failure: $status" unless $d; |
55
|
8
|
|
|
|
|
31
|
$self->{inflater} = $d; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 deflater |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a deflater object, for compressing data. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub deflater { |
65
|
18
|
|
|
18
|
1
|
26
|
my $self = shift; |
66
|
18
|
100
|
|
|
|
67
|
return $self->{deflater} if $self->{deflater}; |
67
|
6
|
|
|
|
|
72
|
my ($d, $status) = Compress::Raw::Zlib::Deflate->new( |
68
|
|
|
|
|
|
|
-WindowBits => 12, |
69
|
|
|
|
|
|
|
-Dictionary => ZLIB_DICTIONARY, |
70
|
|
|
|
|
|
|
); |
71
|
6
|
50
|
|
|
|
4356
|
die "Zlib failure: $status" unless $d; |
72
|
6
|
|
|
|
|
23
|
$self->{deflater} = $d; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 decompress |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Given a scalar containing bytes, this will return the decompressed |
78
|
|
|
|
|
|
|
contents as a scalar, or raise an exception on failure. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub decompress { |
83
|
20
|
|
|
20
|
1
|
36
|
my $self = shift; |
84
|
20
|
|
|
|
|
38
|
my $data = shift; |
85
|
20
|
|
|
|
|
58
|
my $comp = $self->inflater; |
86
|
20
|
|
|
|
|
432
|
my $status = $comp->inflate($data => \my $out); |
87
|
20
|
50
|
|
|
|
98
|
die "Failed: $status" unless $status == Z_OK; |
88
|
20
|
|
|
|
|
166
|
$out; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 compress |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Given a scalar containing bytes, this will return the compressed |
94
|
|
|
|
|
|
|
contents as a scalar, or raise an exception on failure. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub compress { |
99
|
18
|
|
|
18
|
1
|
26
|
my $self = shift; |
100
|
18
|
|
|
|
|
29
|
my $data = shift; |
101
|
18
|
|
|
|
|
61
|
my $comp = $self->deflater; |
102
|
|
|
|
|
|
|
|
103
|
18
|
|
|
|
|
206
|
my $status = $comp->deflate($data => \my $start); |
104
|
18
|
50
|
|
|
|
88
|
die "Failed: $status" unless $status == Z_OK; |
105
|
18
|
|
|
|
|
169
|
$status = $comp->flush(\my $extra => Z_SYNC_FLUSH); |
106
|
18
|
50
|
|
|
|
506
|
die "Failed: $status" unless $status == Z_OK; |
107
|
18
|
|
|
|
|
149
|
return $start . $extra; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |