From ac17e24feca48ee347fc1dbd376beaee7907a75c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 10 Aug 2016 23:45:57 -0400 Subject: add dir? --- src/zip.cr | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') 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 @@ -1519,6 +1519,20 @@ module Zip data_mem_io.close 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. # -- cgit v1.2.3