class ZipContainer::Dir
This class represents a ZipContainer
in directory format. See the OCF and UCF specifications for more details.
This class provides most of the facilities of the standard ::Dir
class. Please also consult the ruby Dir documentation alongside these pages.
There are code examples available with the source code of this library.
Public Class Methods
Create a new (or convert an existing) directory as a ZipContainer
with the specified mimetype.
# File lib/zip-container/dir.rb, line 68 def self.create(pathname, mimetype) ::Dir.mkdir(pathname) unless ::File.directory?(pathname) ::File.write(::File.join(pathname, MIMETYPE_FILE), mimetype) # Now open the newly created container. c = new(pathname) if block_given? begin yield c ensure c.close end end c end
Public Instance Methods
Equal to ::Dir.close
# File lib/zip-container/dir.rb, line 163
Equal to ::Dir.each
# File lib/zip-container/dir.rb, line 171
Equal to ::Dir.path
# File lib/zip-container/dir.rb, line 180
Equal to ::Dir.pos
# File lib/zip-container/dir.rb, line 188
Equal to ::Dir.pos=
# File lib/zip-container/dir.rb, line 196
Provides compatibility between directory and zip containers. If called without any parameters it acts like ::Dir.read but if called with a path then it acts like Zip::File#read.
Please see the documentation of the relevant method for more details.
# File lib/zip-container/dir.rb, line 97 def read(name = nil) return @container.read if name.nil? ::File.read(full_path(name)) end
Equal to ::Dir.rewind
# File lib/zip-container/dir.rb, line 204
Equal to ::Dir.seek
# File lib/zip-container/dir.rb, line 212
Equal to ::Dir.tell
# File lib/zip-container/dir.rb, line 220
Private Instance Methods
Prepend the full path of the directory name to whatever is passed in here. This is for internal use to ensure we are always operating on files within our container directory.
# File lib/zip-container/dir.rb, line 139 def full_path(path) ::File.join(@container.path, path) end
# File lib/zip-container/dir.rb, line 143 def open_container(location) ::Dir.new(location) end
# File lib/zip-container/dir.rb, line 154 def read_mimetype ::File.read(full_path(MIMETYPE_FILE)) end
# File lib/zip-container/dir.rb, line 147 def verify_mimetype mime_path = full_path(MIMETYPE_FILE) return "'mimetype' file is missing." unless ::File.exist?(mime_path) return "'mimetype' is not a regular file" unless ::File.file?(mime_path) return "'mimetype' is not readable." unless ::File.readable?(mime_path) end