Class: InVFS::Zip

Inherits:
Object show all
Defined in:
lib/invfs/zip.rb,
lib/invfs/zip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Zip

Returns a new instance of Zip.



16
17
18
19
20
# File 'lib/invfs/zip.rb', line 16

def initialize(path)
  @path = String(path)
  @zip = ::Zip::File.open(@path)
  @zipfile = @zip.file
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/invfs/zip.rb', line 14

def path
  @path
end

#zipObject (readonly)

Returns the value of attribute zip.



14
15
16
# File 'lib/invfs/zip.rb', line 14

def zip
  @zip
end

#zipfileObject (readonly)

Returns the value of attribute zipfile.



14
15
16
# File 'lib/invfs/zip.rb', line 14

def zipfile
  @zipfile
end

Class Method Details

.open(file) ⇒ Object

call-seq:

open(file) -> VFS object

REQUIRED method for VFS Handler.

Open as VFS.



105
106
107
# File 'lib/invfs/zip.rb', line 105

def Zip.open(file)
  new file
end

.probe(file) ⇒ Object

call-seq:

probe(file) -> true or false

REQUIRED method for VFS Handler.

Check available as VFS.



93
94
95
# File 'lib/invfs/zip.rb', line 93

def Zip.probe(file)
  file.readat(0, 4) == "PK\x03\x04"
end

Instance Method Details

#file?(path) ⇒ Boolean

call-seq:

file?(path) -> true OR false (OR nil)

REQUIRED method for VFS.

Returns:

  • (Boolean)


40
41
42
# File 'lib/invfs/zip.rb', line 40

def file?(path)
  zipfile.file?(path)
end

#inspectObject



71
72
73
# File 'lib/invfs/zip.rb', line 71

def inspect
  %(#<#{self.class}:#{path}>)
end

#pretty_print(q) ⇒ Object



75
76
77
# File 'lib/invfs/zip.rb', line 75

def pretty_print(q)
  q.text inspect
end

#read(path) ⇒ Object

call-seq:

read(path) -> string

REQUIRED method for VFS.



60
61
62
# File 'lib/invfs/zip.rb', line 60

def read(path)
  zipfile.read(path)
end

#size(path) ⇒ Object

call-seq:

size(path) -> integer for file size

REQUIRED method for VFS.



50
51
52
# File 'lib/invfs/zip.rb', line 50

def size(path)
  zipfile.size(path)
end

#to_pathObject

call-seq:

to_path -> string

REQUIRED method for VFS.

This value MUST be not modifying in each objects.



30
31
32
# File 'lib/invfs/zip.rb', line 30

def to_path
  path
end

#to_sObject

optional method for VFS.



67
68
69
# File 'lib/invfs/zip.rb', line 67

def to_s
  %(#{path} (#{self.class}))
end