-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.rb
110 lines (95 loc) · 1.64 KB
/
zip.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!ruby
require "zip/filesystem"
require_relative "../invfs"
using InVFS::Extensions
module InVFS
class Zip
attr_reader :path, :zip, :zipfile
def initialize(path)
@path = String(path)
@zip = ::Zip::File.open(@path)
@zipfile = @zip.file
end
#
# call-seq:
# to_path -> string
#
# REQUIRED method for VFS.
#
# This value MUST be not modifying in each objects.
#
def to_path
path
end
#
# call-seq:
# file?(path) -> true OR false (OR nil)
#
# REQUIRED method for VFS.
#
def file?(path)
zipfile.file?(path)
end
#
# call-seq:
# size(path) -> integer for file size
#
# REQUIRED method for VFS.
#
def size(path)
zipfile.size(path)
end
#
# call-seq:
# read(path) -> string
#
# REQUIRED method for VFS.
#
def read(path)
zipfile.read(path)
end
#
# optional method for VFS.
#
def to_s
%(#{path} (#{self.class}))
end
def inspect
%(#<#{self.class}:#{path}>)
end
def pretty_print(q)
q.text inspect
end
end
class Zip
#
# VFS Handler Methods
;
#
# call-seq:
# probe(file) -> true or false
#
# REQUIRED method for VFS Handler.
#
# Check available as VFS.
#
def Zip.probe(file)
file.readat(0, 4) == "PK\x03\x04"
end
#
# call-seq:
# open(file) -> VFS object
#
# REQUIRED method for VFS Handler.
#
# Open as VFS.
#
def Zip.open(file)
new file
end
#
# Regist handler as VFS.
#
InVFS.regist self
end
end