| 1 | package MIME::Decoder::Gzip64; | ||||||||||||
| 2 | |||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | MIME::Decoder::Gzip64 - decode a "base64" gzip stream | ||||||||||||
| 7 | |||||||||||||
| 8 | |||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||
| 10 | |||||||||||||
| 11 | A generic decoder object; see L<MIME::Decoder> for usage. | ||||||||||||
| 12 | |||||||||||||
| 13 | |||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||
| 15 | |||||||||||||
| 16 | A MIME::Decoder::Base64 subclass for a nonstandard encoding whereby | ||||||||||||
| 17 | data are gzipped, then the gzipped file is base64-encoded. | ||||||||||||
| 18 | Common non-standard MIME encodings for this: | ||||||||||||
| 19 | |||||||||||||
| 20 | x-gzip64 | ||||||||||||
| 21 | |||||||||||||
| 22 | Since this class relies on external programs which may not | ||||||||||||
| 23 | exist on your machine, MIME-tools does not "install" it by default. | ||||||||||||
| 24 | To use it, you need to say in your main program: | ||||||||||||
| 25 | |||||||||||||
| 26 | install MIME::Decoder::Gzip64 'x-gzip64'; | ||||||||||||
| 27 | |||||||||||||
| 28 | Note: if this class isn't working for you, you may need to change the | ||||||||||||
| 29 | commands it runs. In your main program, you can do so by setting up | ||||||||||||
| 30 | the two commands which handle the compression/decompression. | ||||||||||||
| 31 | |||||||||||||
| 32 | use MIME::Decoder::Gzip64; | ||||||||||||
| 33 | |||||||||||||
| 34 | $MIME::Decoder::Gzip64::GZIP = 'gzip -c'; | ||||||||||||
| 35 | $MIME::Decoder::Gzip64::GUNZIP = 'gzip -d -c'; | ||||||||||||
| 36 | |||||||||||||
| 37 | =head1 SEE ALSO | ||||||||||||
| 38 | |||||||||||||
| 39 | L<MIME::Decoder> | ||||||||||||
| 40 | |||||||||||||
| 41 | =head1 AUTHOR | ||||||||||||
| 42 | |||||||||||||
| 43 | Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>). | ||||||||||||
| 44 | |||||||||||||
| 45 | All rights reserved. This program is free software; you can redistribute | ||||||||||||
| 46 | it and/or modify it under the same terms as Perl itself. | ||||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | =cut | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 1 | require 5.002; | |||||||||||
| 53 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 54 | 1 | ▶ | use vars qw(@ISA $VERSION $GZIP $GUNZIP); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 55 | 1 | ▶ | use MIME::Decoder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 56 | 1 | ▶ | use MIME::Base64; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 57 | 1 | ▶ | use MIME::Decoder::Base64; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 58 | 1 | ▶ | use MIME::Tools qw(tmpopen whine); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 59 | |||||||||||||
| 60 | # Inheritance: | ||||||||||||
| 61 | 1 | @ISA = qw(MIME::Decoder::Base64); | |||||||||||
| 62 | |||||||||||||
| 63 | # The package version, both in 1.23 style *and* usable by MakeMaker: | ||||||||||||
| 64 | 1 | $VERSION = "5.522"; | |||||||||||
| 65 | |||||||||||||
| 66 | # How to compress stdin to stdout: | ||||||||||||
| 67 | 1 | $GZIP = "gzip -c"; | |||||||||||
| 68 | |||||||||||||
| 69 | # How to UNcompress stdin to stdout: | ||||||||||||
| 70 | 1 | $GUNZIP = "gzip -d -c"; | |||||||||||
| 71 | |||||||||||||
| 72 | |||||||||||||
| 73 | #------------------------------ | ||||||||||||
| 74 | # | ||||||||||||
| 75 | # decode_it IN, OUT | ||||||||||||
| 76 | # | ||||||||||||
| 77 | 1 | ▶ | sub decode_it { | ||||||||||
|
Subroutine
decode_it: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 78 | 1 | my ($self, $in, $out) = @_; | |||||||||||
| 79 | |||||||||||||
| 80 | # Open a temp file (assume the worst, that this is a big stream): | ||||||||||||
| 81 | 1 | ▶ | my $tmp = tmpopen() || die "can't get temp file"; | ||||||||||
|
Condition50%1/2
tmpopen() || die(q[can't get temp file])
MC/DC0%0/1
tmpopen() || die(q[can't get temp file])
tmpopen()
Truth table50%1/2
A
A= tmpopen()
| |||||||||||||
| 82 | |||||||||||||
| 83 | # Stage 1: decode the base64'd stream into zipped data: | ||||||||||||
| 84 | 1 | ▶ | $self->SUPER::decode_it($in, $tmp) or die "base64 decoding failed!"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | |||||||||||||
| 86 | # Stage 2: un-zip the zipped data: | ||||||||||||
| 87 | 1 | $tmp->seek(0, 0); | |||||||||||
| 88 | 1 | ▶ | $self->filter($tmp, $out, $GUNZIP) or die "gzip decoding failed!"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | #------------------------------ | ||||||||||||
| 92 | # | ||||||||||||
| 93 | # encode_it IN, OUT | ||||||||||||
| 94 | # | ||||||||||||
| 95 | 1 | ▶ | sub encode_it { | ||||||||||
|
Subroutine
encode_it: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||
| 96 | 1 | my ($self, $in, $out) = @_; | |||||||||||
| 97 | 1 | whine "Encoding ", $self->encoding, " is not standard MIME!"; | |||||||||||
| 98 | |||||||||||||
| 99 | # Open a temp file (assume the worst, that this is a big stream): | ||||||||||||
| 100 | 1 | ▶ | my $tmp = tmpopen() || die "can't get temp file"; | ||||||||||
|
Condition50%1/2
tmpopen() || die(q[can't get temp file])
MC/DC0%0/1
tmpopen() || die(q[can't get temp file])
tmpopen()
Truth table50%1/2
A
A= tmpopen()
| |||||||||||||
| 101 | |||||||||||||
| 102 | # Stage 1: zip the raw data: | ||||||||||||
| 103 | 1 | ▶ | $self->filter($in, $tmp, $GZIP) or die "gzip encoding failed!"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | |||||||||||||
| 105 | # Stage 2: encode the zipped data via base64: | ||||||||||||
| 106 | 1 | $tmp->seek(0, 0); | |||||||||||
| 107 | 1 | ▶ | $self->SUPER::encode_it($tmp, $out) or die "base64 encoding failed!"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | #------------------------------ | ||||||||||||
| 111 | 1 | 1; | |||||||||||