aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-10 23:45:57 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-10 23:45:57 -0400
commitac17e24feca48ee347fc1dbd376beaee7907a75c (patch)
tree3a110a545d8e1ef06d5233d14c96b12b705121b6
parent82dafe047ec701ecd8d62c8088152fe2c4ab1a5d (diff)
downloadzip-crystal-ac17e24feca48ee347fc1dbd376beaee7907a75c.tar.bz2
zip-crystal-ac17e24feca48ee347fc1dbd376beaee7907a75c.zip
add dir?
-rw-r--r--spec/zip_spec.cr13
-rw-r--r--src/zip.cr16
2 files changed, 23 insertions, 6 deletions
diff --git a/spec/zip_spec.cr b/spec/zip_spec.cr
index 01a98ff..0ca4e86 100644
--- a/spec/zip_spec.cr
+++ b/spec/zip_spec.cr
@@ -91,12 +91,15 @@ describe Zip do
it "reads all an archive's compressed entries" do
Zip.read(File.join(TEST_DIR, "test-many.zip")) do |zip|
zip.each do |e|
- pp e.path
- io = MemoryIO.new
- # e.write(STDOUT)
- e.write(io)
- io.close
+ if e.dir?
+ puts "#{e.path} is a directory"
+ else
+ io = MemoryIO.new
+ # e.write(STDOUT)
+ e.write(io)
+ io.close
+ end
end
end
end
diff --git a/src/zip.cr b/src/zip.cr
index a2316aa..be5fa56 100644
--- a/src/zip.cr
+++ b/src/zip.cr
@@ -11,7 +11,7 @@ require "zlib"
# [x] convert datetime to Time
# [x] add size to Entry
# [x] Version
-# [ ] directories
+# [x] directories
# [ ] full tests
# [ ] zip64
# [ ] legacy unicode (e.g., non-bit 11) path/comment support
@@ -1520,6 +1520,20 @@ module Zip
end
#
+ # Returns true if this entry a directory.
+ #
+ # Example:
+ #
+ # Zip.read("foo.zip") do |zip|
+ # type = zip["some-dir/"].dir? ? "directory" : "file"
+ # puts "#{path} is a #{type}"
+ # end
+ #
+ def dir? : Bool
+ (@external_attr & 0x01) != 0
+ end
+
+ #
# Return the uncompressed size of this entry in bytes.
#
# Example: