Class: RubyArchive::Handlers::ZipHandler
- Inherits:
-
RubyArchive::Handler
- Object
- RubyArchive::Handler
- RubyArchive::Handlers::ZipHandler
- Defined in:
- lib/ruby_archive/handlers/zip_handler.rb
Constant Summary collapse
- ZIP_MAGIC =
"\x50\x4B\x03\x04"
Instance Attribute Summary
Attributes inherited from RubyArchive::Handler
Class Method Summary collapse
-
.handles?(location) ⇒ Boolean
Checks the magic of the given file to check if it’s a zip file.
Instance Method Summary collapse
- #close ⇒ Object
- #dir ⇒ Object
- #file ⇒ Object
-
#initialize(location) ⇒ ZipHandler
constructor
A new instance of ZipHandler.
Methods inherited from RubyArchive::Handler
Constructor Details
#initialize(location) ⇒ ZipHandler
Returns a new instance of ZipHandler.
21 22 23 24 25 26 |
# File 'lib/ruby_archive/handlers/zip_handler.rb', line 21 def initialize location # use normalized location because Zip::ZipFile.open does not expand '~' normalized_location = RubyArchive::Handler::normalize_path(location) @zipfs = Zip::ZipFile.open(normalized_location) @name = normalized_location end |
Class Method Details
.handles?(location) ⇒ Boolean
Checks the magic of the given file to check if it’s a zip file
13 14 15 16 17 18 19 |
# File 'lib/ruby_archive/handlers/zip_handler.rb', line 13 def self.handles? location # use normalized location because Zip::ZipFile.open does not expand '~' normalized_location = RubyArchive::Handler::normalize_path(location) return false unless File.file?(normalized_location) return false unless File.read(normalized_location, ZIP_MAGIC.length) == ZIP_MAGIC return true end |
Instance Method Details
#close ⇒ Object
28 29 30 |
# File 'lib/ruby_archive/handlers/zip_handler.rb', line 28 def close @zipfs.close end |
#dir ⇒ Object
36 37 38 |
# File 'lib/ruby_archive/handlers/zip_handler.rb', line 36 def dir @zipfs.dir end |
#file ⇒ Object
32 33 34 |
# File 'lib/ruby_archive/handlers/zip_handler.rb', line 32 def file @zipfs.file end |