summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-06 12:55:52 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-06 12:55:52 -0400
commit0584c5d628f34b5d2edb2a075774e0d457423bd2 (patch)
treed195ea19ed775d54264b57a2fa34e077d90d78b4
parent15c29c1cd019be5689e0f5ded3b0d94e677c3060 (diff)
downloadzip-crystal-0584c5d628f34b5d2edb2a075774e0d457423bd2.tar.bz2
zip-crystal-0584c5d628f34b5d2edb2a075774e0d457423bd2.zip
add variants
-rw-r--r--spec/zip_spec.cr6
-rw-r--r--src/zip.cr22
2 files changed, 27 insertions, 1 deletions
diff --git a/spec/zip_spec.cr b/spec/zip_spec.cr
index 74066b7..0ace290 100644
--- a/spec/zip_spec.cr
+++ b/spec/zip_spec.cr
@@ -1,5 +1,7 @@
require "./spec_helper"
+TEST_DIR = File.dirname(__FILE__)
+
describe Zip do
# TODO: Write tests
@@ -9,7 +11,9 @@ describe Zip do
end
describe Zip::Writer do
- Zip.write("test.zip") do |zip|
+ Zip.write(File.join(TEST_DIR, "test.zip")) do |zip|
zip.add("foo.txt", MemoryIO.new("foo"))
+ zip.add("bar.txt", "bar")
+ zip.add_file("shard.yml", File.join(TEST_DIR, "..", "shard.yml"))
end
end
diff --git a/src/zip.cr b/src/zip.cr
index 43fc4c7..5c2acfb 100644
--- a/src/zip.cr
+++ b/src/zip.cr
@@ -516,6 +516,28 @@ module Zip
@pos - src_pos
end
+ def add(
+ path : String,
+ body : String | Bytes,
+ method : CompressionMethod = CompressionMethod::DEFLATE,
+ time : Time = Time.now,
+ comment : String = "",
+ ) : UInt64
+ add(path, MemoryIO.new(body), method, time, comment)
+ end
+
+ def add_file(
+ path : String,
+ file_path : String,
+ method : CompressionMethod = CompressionMethod::DEFLATE,
+ time : Time = Time.now,
+ comment : String = "",
+ ) : UInt64
+ File.open(file_path, "rb") do |io|
+ add(path, io, method, time, comment)
+ end
+ end
+
# 4.3.16 End of central directory record:
#
# end of central dir signature 4 bytes (0x06054b50)