Class: ZipContainer::Dir
- Extended by:
- Forwardable
- Defined in:
- lib/zip-container/dir.rb
Overview
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.
Defined Under Namespace
Classes: Entries
Constant Summary
Constants inherited from Container
Instance Attribute Summary
Attributes inherited from Container
Class Method Summary collapse
-
.create(pathname, mimetype) ⇒ Object
:call-seq: create(pathname, mimetype) -> container create(pathname, mimetype) {|container| …}.
Instance Method Summary collapse
-
#entries ⇒ Object
:stopdoc: For internal use only! This method and the Entry and Entries classes provide compatibility between zip-style and dir-style entries.
-
#initialize(location) ⇒ Dir
constructor
:stopdoc:.
-
#read(name = nil) ⇒ Object
:call-seq: read read(path) -> file contents.
Methods inherited from Container
open, verify, #verify, verify!, #verify!, verify?, #verify?
Methods included from ManagedEntries
#hidden_directory?, #hidden_entry?, #hidden_file?, #managed_directories, #managed_directory?, #managed_directory_names, #managed_entries, #managed_entry?, #managed_entry_names, #managed_file?, #managed_file_names, #managed_files, #verify_managed_entries, #verify_managed_entries!
Methods included from Util
Methods included from ReservedNames
#reserved_entry?, #reserved_names
Constructor Details
#initialize(location) ⇒ Dir
:stopdoc:
57 58 59 |
# File 'lib/zip-container/dir.rb', line 57 def initialize(location) super(location) end |
Class Method Details
.create(pathname, mimetype) ⇒ Object
:call-seq:
create(pathname, mimetype) -> container
create(pathname, mimetype) {|container| ...}
Create a new (or convert an existing) directory as a ZipContainer with the specified mimetype.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 |
Instance Method Details
#entries ⇒ Object
:stopdoc: For internal use only! This method and the Entry and Entries classes provide compatibility between zip-style and dir-style entries
107 108 109 |
# File 'lib/zip-container/dir.rb', line 107 def entries Entries.new(@container) end |
#read(name = nil) ⇒ Object
:call-seq:
read
read(path) -> file contents
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.
97 98 99 100 101 |
# File 'lib/zip-container/dir.rb', line 97 def read(name = nil) return @container.read if name.nil? ::File.read(full_path(name)) end |