Skip to content

Commit

Permalink
Add test for add filehandle
Browse files Browse the repository at this point in the history
  • Loading branch information
pmqs committed Mar 10, 2019
1 parent 2d4227b commit 9f06d90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Archive/SimpleZip.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class SimpleZip is export
$obj.add("payload data here", :name<data1>);
$obj.add(Blob.new([2,4,6]), :name<data1>);
# Drop a filehandle into the zip archive
my $handle = "some file".IO.open;
$obj.add($handle, :name<data2>);
$obj.close();
=DESCRIPTION
Expand Down Expand Up @@ -339,7 +343,7 @@ IO::Path
# Add a file to the zip archive
$zip.add("/tmp/fred".IO);
To add a string/blob to
To add a string/blob to the archive
# Add a string to the zip archive
$zip.add("payload data here", :name<data1>);
Expand Down
6 changes: 6 additions & 0 deletions t/002-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ ok mkdir $dir1, 0o777;
my $zipfile = "test.zip" ;
my $datafile = "$dir1/data123";
my $datafile1 = "data124";
my $datafile2 = "data125".IO;

subtest
{
unlink $zipfile;
spurt $datafile, "some data" ;
spurt $datafile1, "more data" ;
my $text = "line 1\nline 2\nline 3";

spurt $datafile2, $text ;

ok $datafile.IO.e, "$datafile does exists";
nok $zipfile.IO.e, "$zipfile does not exists";
Expand All @@ -52,6 +56,7 @@ subtest
ok $zip.add("abcde", :name<fred>, comment => 'member comment'), "add string ok";
ok $zip.add("def", :name</joe//bad>, :method(Zip-CM-Store), :stream, :!canonical-name), "add string, STORE";
ok $zip.add(Buf.new([2,4,6]), :name</jim/>, :method(Zip-CM-Bzip2), :stream), "add string, STORE";
ok $zip.add($datafile2.open, :name<handle>), "Add filehandle";
ok $zip.close(), "closed";

ok $zipfile.IO.e, "$zipfile exists";
Expand All @@ -64,6 +69,7 @@ subtest
is pipe-in-from-unzip($zipfile, "fred"), "abcde", "member fred ok";
is pipe-in-from-unzip($zipfile, "/joe//bad"), "def", "member /joe//bad ok";
is pipe-in-from-unzip($zipfile, "jim", :binary).decode, "\x2\x4\x6", "member jim ok";
is pipe-in-from-unzip($zipfile, "handle"), $text, "member handle ok";

# Write zip to Blob

Expand Down

0 comments on commit 9f06d90

Please sign in to comment.