| 1 | package Archive::StringToZip; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use vars qw(@ISA @EXPORT_OK $VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use IO::String (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use base qw(Archive::Zip); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | require Exporter; | |||||||||
| 12 | 4 | @ISA = qw(Exporter Archive::Zip::Archive Archive::Zip); | |||||||||
| 13 | 4 | @EXPORT_OK = qw(zipString); | |||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 4 | $VERSION = '1.03'; | |||||||||
| 17 | |||||||||||
| 18 | 8 | ▶ | sub zipString { | ||||||||
|
Subroutine
zipString: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 19 | 8 | ▶ | my $self = ref($_[0]) ? shift : __PACKAGE__->new(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 8 | my ($string, $filename) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 8 | ▶ | croak 'Cannot archive an undefined string' unless defined $string; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 5 | ▶ | $filename = 'file.txt' unless $filename; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | 5 | my $SH = IO::String->new(); | |||||||||
| 26 | |||||||||||
| 27 | 5 | my $member = $self->addString($string, $filename); | |||||||||
| 28 | 5 | $member->desiredCompressionMethod(COMPRESSION_DEFLATED); | |||||||||
| 29 | 5 | $member->desiredCompressionLevel( 9 ); | |||||||||
| 30 | |||||||||||
| 31 | 5 | my $status = $self->writeToFileHandle($SH); | |||||||||
| 32 | 5 | ▶ | die $! if $status != AZ_OK; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 5 | binmode STDOUT; # necessary for Win32 and does no harm on *nix | |||||||||
| 35 | 5 | $SH->setpos(0); | |||||||||
| 36 | 5 | return do { local $/ = undef; $SH->getline }; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 4 | 1; | |||||||||
| 40 | |||||||||||
| 41 | __END__ | ||||||||||