Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 4 | use File::Spec::Functions qw/catfile/; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 5 | use IO::Uncompress::Unzip; |
| 6 | |
| 7 | use FindBin; |
| 8 | BEGIN { |
| 9 | unshift @INC, "$FindBin::Bin/../lib"; |
| 10 | }; |
| 11 | |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame^] | 12 | use Test::KorAP::XML::TEI qw!korap_tempfile!; |
| 13 | |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 14 | require_ok('KorAP::XML::TEI::Zipper'); |
| 15 | |
| 16 | my $data; |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 17 | my ($fh, $outzip) = korap_tempfile('zipper'); |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 18 | |
| 19 | my $zip = KorAP::XML::TEI::Zipper->new($outzip); |
Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 20 | $fh->close; |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 21 | |
| 22 | ok($zip, 'Zipper initialized'); |
| 23 | |
| 24 | ok($zip->new_stream('data/file1.txt')->print('hello'), 'Write to initial stream'); |
| 25 | ok($zip->new_stream('data/file2.txt')->print('world'), 'Write to appended stream'); |
| 26 | |
| 27 | $zip->close; |
| 28 | |
| 29 | ok(-e $outzip, 'Zip exists'); |
| 30 | |
| 31 | # Uncompress GOE/header.xml from zip file |
| 32 | my $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file1.txt'); |
| 33 | |
| 34 | $data .= $unzip->getline while !$unzip->eof; |
| 35 | ok($unzip->close, 'Closed'); |
| 36 | |
| 37 | is($data, 'hello', 'Data correct'); |
| 38 | |
| 39 | |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame^] | 40 | # Uncompress data/file2.txt from zip file |
Akron | 8571751 | 2020-07-08 11:19:19 +0200 | [diff] [blame] | 41 | $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file2.txt'); |
| 42 | |
| 43 | $data = ''; |
| 44 | $data .= $unzip->getline while !$unzip->eof; |
| 45 | ok($unzip->close, 'Closed'); |
| 46 | |
| 47 | is($data, 'world', 'Data correct'); |
| 48 | |
| 49 | done_testing; |