line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Memcached::Client::Compressor::Gzip; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
640
|
$Memcached::Client::Compressor::Gzip::VERSION = '2.01'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
#ABSTRACT: Implements Memcached Compression using Gzip |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4661
|
use bytes; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
30
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
10
|
1
|
|
|
1
|
|
584
|
use Memcached::Client::Log qw{DEBUG}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
11
|
1
|
|
|
1
|
|
7
|
use base qw{Memcached::Client::Compressor}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
889
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant +{ |
14
|
1
|
|
|
|
|
3
|
HAVE_ZLIB => eval { require Compress::Zlib; 1 }, |
|
1
|
|
|
|
|
1444
|
|
|
1
|
|
|
|
|
156437
|
|
15
|
|
|
|
|
|
|
F_COMPRESS => 2, |
16
|
|
|
|
|
|
|
COMPRESS_SAVINGS => 0.20 |
17
|
1
|
|
|
1
|
|
9
|
}; |
|
1
|
|
|
|
|
1
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub decompress { |
20
|
4
|
|
|
4
|
1
|
12
|
my ($self, $data, $flags) = @_; |
21
|
|
|
|
|
|
|
|
22
|
4
|
100
|
|
|
|
22
|
return unless defined $data; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
100
|
|
|
18
|
$flags ||= 0; |
25
|
|
|
|
|
|
|
|
26
|
3
|
100
|
100
|
|
|
17
|
if ($flags & F_COMPRESS && HAVE_ZLIB) { |
27
|
1
|
|
|
|
|
1
|
$self->log ("Uncompressing data") if DEBUG; |
28
|
1
|
|
|
|
|
6
|
$data = Compress::Zlib::memGunzip ($data); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
572
|
return ($data, $flags); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub compress { |
35
|
4
|
|
|
4
|
1
|
1013
|
my ($self, $data, $flags) = @_; |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
6
|
$self->log ("Entering compress") if DEBUG; |
38
|
4
|
100
|
|
|
|
24
|
return unless defined $data; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
5
|
$self->log ("Have data") if DEBUG; |
41
|
3
|
|
|
|
|
19
|
my $len = bytes::length ($data); |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
1231
|
$self->log ("Checking for Zlib") if DEBUG; |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
7
|
if (HAVE_ZLIB) { |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
66
|
|
|
27
|
my $compressable = $self->{compress_threshold} && $len >= $self->{compress_threshold}; |
48
|
|
|
|
|
|
|
|
49
|
3
|
100
|
|
|
|
10
|
if ($compressable) { |
50
|
1
|
|
|
|
|
3
|
$self->log ("Compressing data") if DEBUG; |
51
|
1
|
|
|
|
|
5
|
my $c_val = Compress::Zlib::memGzip ($data); |
52
|
1
|
|
|
|
|
524
|
my $c_len = bytes::length ($c_val); |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
11
|
if ($c_len < $len * (1 - COMPRESS_SAVINGS)) { |
55
|
1
|
|
|
|
|
1
|
$self->log ("Compressing is a win") if DEBUG; |
56
|
1
|
|
|
|
|
3
|
$data = $c_val; |
57
|
1
|
|
|
|
|
4
|
$flags |= F_COMPRESS; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
32
|
return ($data, $flags); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |