argh, clean out copy
[supertux.git] / src / unison / physfs-1.1.1 / extras / physfs_rb / physfs / physfs.rb
1 #
2 # PhysicsFS - ruby interface
3 #
4 # Author: Ed Sinjiashvili (slimb@vlinkmail.com)
5 # License: LGPL
6 #
7
8 require 'physfs_so'
9
10 module PhysicsFS
11
12   class Version
13     def initialize major, minor, patch
14       @major = major
15       @minor = minor
16       @patch = patch
17     end
18
19     attr_reader :major, :minor, :patch
20
21     def to_s
22       "#@major.#@minor.#@patch"
23     end
24   end
25
26   class ArchiveInfo
27     def initialize ext, desc, author, url
28       @extension = ext
29       @description = desc
30       @author = author
31       @url = url
32     end
33
34     attr_reader :extension, :description
35     attr_reader :author, :url
36
37     def to_s
38       " * #@extension: #@description\n    Written by #@author.\n    #@url\n"
39     end
40   end
41
42   #
43   # convenience methods
44   #
45   class << self  
46
47     def init argv0 = $0
48       init_internal argv0
49     end
50
51     def append_search_path str
52       add_to_search_path str, 1
53       self
54     end
55
56     def prepend_search_path str
57       add_to_search_path str, 0
58       self
59     end
60
61     alias_method :<<,      :append_search_path
62     alias_method :push,    :append_search_path
63     alias_method :unshift, :prepend_search_path
64
65     def ls path = ""
66       enumerate path
67     end
68   end
69
70   #
71   # File - PhysicsFS abstract file - can be drawn from various sources
72   # 
73   class File
74     def write_str str
75       write str, 1, str.length
76     end
77     
78     def cat
79       prev_pos = tell
80       seek 0
81       r = read length, 1
82       seek prev_pos
83       r
84     end
85     
86     alias_method :size, :length
87   end
88
89   #
90   # RWops - general stdio like operations on file-like creatures
91   #
92   class RWops
93     SEEK_SET = 0
94     SEEK_CUR = 1
95     SEEK_END = 2
96
97     # tell current position of RWopted entity
98     def tell
99       seek 0, SEEK_CUR
100     end
101
102     # length of RWops abstracted entity
103     def length
104       cur = tell
105       r = seek 0, SEEK_END
106       seek cur, SEEK_SET
107       r
108     end
109
110     alias_method :size, :length
111
112     #
113     # create rwops from PhysicsFS file object
114     # 
115     def self.from_physfs file
116       file.to_rwops
117     end
118   end
119 end
120
121 # physfs.rb ends here #