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.



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

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.



10
11
12
# File 'lib/invfs/zip.rb', line 10

def path
  @path
end

#zipObject (readonly)

Returns the value of attribute zip.



10
11
12
# File 'lib/invfs/zip.rb', line 10

def zip
  @zip
end

#zipfileObject (readonly)

Returns the value of attribute zipfile.



10
11
12
# File 'lib/invfs/zip.rb', line 10

def zipfile
  @zipfile
end

Class Method Details

.open(file) ⇒ Object

call-seq:

open(file) -> VFS object

REQUIRED method for VFS Handler.

Open as VFS.



101
102
103
# File 'lib/invfs/zip.rb', line 101

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.



89
90
91
# File 'lib/invfs/zip.rb', line 89

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)


36
37
38
# File 'lib/invfs/zip.rb', line 36

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

#inspectObject



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

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

#pretty_print(q) ⇒ Object



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

def pretty_print(q)
  q.text inspect
end

#read(path) ⇒ Object

call-seq:

read(path) -> string

REQUIRED method for VFS.



56
57
58
# File 'lib/invfs/zip.rb', line 56

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

#size(path) ⇒ Object

call-seq:

size(path) -> integer for file size

REQUIRED method for VFS.



46
47
48
# File 'lib/invfs/zip.rb', line 46

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.



26
27
28
# File 'lib/invfs/zip.rb', line 26

def to_path
  path
end

#to_sObject

optional method for VFS.



63
64
65
# File 'lib/invfs/zip.rb', line 63

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