Skip to content

Latest commit

 

History

History
121 lines (98 loc) · 2 KB

physfs.rb

File metadata and controls

121 lines (98 loc) · 2 KB
 
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
111
112
113
114
115
116
117
118
119
120
121
#
# PhysicsFS - ruby interface
#
# Author: Ed Sinjiashvili (slimb@vlinkmail.com)
# License: LGPL
#
require 'physfs_so'
module PhysicsFS
class Version
def initialize major, minor, patch
@major = major
@minor = minor
@patch = patch
end
attr_reader :major, :minor, :patch
def to_s
"#@major.#@minor.#@patch"
end
end
class ArchiveInfo
def initialize ext, desc, author, url
@extension = ext
@description = desc
@author = author
@url = url
end
attr_reader :extension, :description
attr_reader :author, :url
def to_s
" * #@extension: #@description\n Written by #@author.\n #@url\n"
end
end
#
# convenience methods
#
class << self
def init argv0 = $0
init_internal argv0
end
def append_search_path str
add_to_search_path str, 1
self
end
def prepend_search_path str
add_to_search_path str, 0
self
end
alias_method :<<, :append_search_path
alias_method :push, :append_search_path
alias_method :unshift, :prepend_search_path
def ls path = ""
enumerate path
end
end
#
# File - PhysicsFS abstract file - can be drawn from various sources
#
class File
def write_str str
write str, 1, str.length
end
def cat
prev_pos = tell
seek 0
r = read length, 1
seek prev_pos
r
end
alias_method :size, :length
end
#
# RWops - general stdio like operations on file-like creatures
#
class RWops
SEEK_SET = 0
SEEK_CUR = 1
SEEK_END = 2
# tell current position of RWopted entity
def tell
seek 0, SEEK_CUR
end
# length of RWops abstracted entity
def length
cur = tell
r = seek 0, SEEK_END
seek cur, SEEK_SET
r
end
alias_method :size, :length
#
# create rwops from PhysicsFS file object
#
def self.from_physfs file
file.to_rwops
end
end
end
# physfs.rb ends here #