File Coverage

blib/lib/MIME/Decoder/Gzip64.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 8 50.0
condition 2 4 50.0
subroutine 8 8 100.0
pod 2 2 100.0
total 45 51 88.2


line stmt bran cond sub pod time code
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 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
40              
41             =head1 AUTHOR
42              
43             Eryq (F), ZeeGee Software Inc (F).
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             require 5.002;
53 1     1   979 use strict;
  1         2  
  1         49  
54 1     1   4 use vars qw(@ISA $VERSION $GZIP $GUNZIP);
  1         2  
  1         90  
55 1     1   4 use MIME::Decoder;
  1         23  
  1         21  
56 1     1   498 use MIME::Base64;
  1         611  
  1         72  
57 1     1   425 use MIME::Decoder::Base64;
  1         1  
  1         24  
58 1     1   4 use MIME::Tools qw(tmpopen whine);
  1         1  
  1         180  
59              
60             # Inheritance:
61             @ISA = qw(MIME::Decoder::Base64);
62              
63             # The package version, both in 1.23 style *and* usable by MakeMaker:
64             $VERSION = "5.509";
65              
66             # How to compress stdin to stdout:
67             $GZIP = "gzip -c";
68              
69             # How to UNcompress stdin to stdout:
70             $GUNZIP = "gzip -d -c";
71              
72              
73             #------------------------------
74             #
75             # decode_it IN, OUT
76             #
77             sub decode_it {
78 1     1 1 1 my ($self, $in, $out) = @_;
79              
80             # Open a temp file (assume the worst, that this is a big stream):
81 1   50     8 my $tmp = tmpopen() || die "can't get temp file";
82              
83             # Stage 1: decode the base64'd stream into zipped data:
84 1 50       388 $self->SUPER::decode_it($in, $tmp) or die "base64 decoding failed!";
85            
86             # Stage 2: un-zip the zipped data:
87 1         5 $tmp->seek(0, 0);
88 1 50       26 $self->filter($tmp, $out, $GUNZIP) or die "gzip decoding failed!";
89             }
90              
91             #------------------------------
92             #
93             # encode_it IN, OUT
94             #
95             sub encode_it {
96 1     1 1 2 my ($self, $in, $out) = @_;
97 1         3 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   50     4 my $tmp = tmpopen() || die "can't get temp file";
101            
102             # Stage 1: zip the raw data:
103 1 50       705 $self->filter($in, $tmp, $GZIP) or die "gzip encoding failed!";
104            
105             # Stage 2: encode the zipped data via base64:
106 1         21 $tmp->seek(0, 0);
107 1 50       141 $self->SUPER::encode_it($tmp, $out) or die "base64 encoding failed!";
108             }
109              
110             #------------------------------
111             1;