Created
February 13, 2020 17:03
-
-
Save cghiban/50bb898984f003ad0a54241c67a5ab88 to your computer and use it in GitHub Desktop.
gzip-freeze-thaw-ungzip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use IO::Compress::Gzip qw(gzip $GzipError); | |
use IO::Uncompress::Gunzip qw(gunzip $GunzipError); | |
use Storable qw(nfreeze thaw); | |
use IO::Scalar (); | |
my $input = "ABC" x 200 . "A" x 2000; | |
my $output = ""; | |
my $gh = IO::Scalar->new(\$output); | |
print length($input), $/; | |
gzip \$input => $gh | |
or die "gzip failed: $GzipError\n"; | |
print length($output), $/; | |
my $data_to_send = nfreeze(\$output); | |
print length($data_to_send), $/; | |
my $data_received = thaw $data_to_send; | |
print length($$data_received), $/; | |
my $ungzipped_data = ''; | |
gunzip $data_received => \$ungzipped_data; | |
print length($ungzipped_data), $/; | |
print "same data: ", $input eq $ungzipped_data, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment