-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathde_com.pl
40 lines (36 loc) · 1.01 KB
/
de_com.pl
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
#!/usr/bin/perl
https://github.com/spjspj/perl_scripts/blob/master/de_com.pl
use Compress::Raw::Zlib;
use strict;
use warnings;
sub compress
{
my $input = $_ [0];
my $deflate;
$deflate = Compress::Raw::Zlib::Deflate->new
(
-WindowBits => 15,
-AppendOutput => 1
);
my $compressed_bytes = '';
my $status = $deflate->deflate($input, $compressed_bytes);
$status = $deflate->flush($compressed_bytes);
my $hcb = unpack("H*", $compressed_bytes);
my $compressed = pack("H*", $hcb);
return $compressed;
}
sub decompress
{
my $compressed = $_ [0];
my $decompressed;
my $inflate = Compress::Raw::Zlib::Inflate->new ();
my $status = $inflate->inflate($compressed, $decompressed);
return $decompressed;
}
# Main
{
my $input = "This is a test string to be compressed and decompressed.";
my $compressed = compress ($input);
my $decompressed = decompress ($compressed);
print $decompressed;
}