rio 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. data/README +18 -12
  2. data/Rakefile +57 -87
  3. data/build_doc.rb +19 -17
  4. data/doc/ANNOUNCE +3 -32
  5. data/doc/RELEASE_NOTES +4 -5
  6. data/doc/RIOIS +215 -0
  7. data/doc/generators/template/html/rio.css +428 -0
  8. data/doc/generators/template/html/rio.rb +18 -389
  9. data/doc/generators/template/html/ugly.rb +130 -0
  10. data/doc/pkg_def.rb +66 -0
  11. data/ex/catcsv.rb +64 -0
  12. data/ex/colx.rb +8 -0
  13. data/ex/findinruby +15 -0
  14. data/ex/findruby +14 -0
  15. data/ex/passwd_report.rb +8 -0
  16. data/ex/prompt.rb +25 -0
  17. data/ex/rgb.txt.gz +0 -0
  18. data/ex/riocat +42 -0
  19. data/ex/riogunzip +31 -0
  20. data/ex/riogzip +24 -0
  21. data/ex/rioprompt.rb +10 -0
  22. data/ex/targz2zip +17 -0
  23. data/ex/tonl +10 -0
  24. data/lib/rio.rb +16 -10
  25. data/lib/rio/abstract_method.rb +3 -4
  26. data/lib/rio/argv.rb +3 -4
  27. data/lib/rio/arycopy.rb +3 -4
  28. data/lib/rio/assert.rb +3 -4
  29. data/lib/rio/base.rb +3 -4
  30. data/lib/rio/callstr.rb +3 -4
  31. data/lib/rio/const.rb +3 -4
  32. data/lib/rio/construct.rb +3 -4
  33. data/lib/rio/constructor.rb +12 -8
  34. data/lib/rio/context.rb +15 -30
  35. data/lib/rio/context/autoclose.rb +3 -4
  36. data/lib/rio/context/copying.rb +3 -4
  37. data/lib/rio/context/cxx.rb +3 -4
  38. data/lib/rio/context/dir.rb +3 -4
  39. data/lib/rio/context/gzip.rb +3 -4
  40. data/lib/rio/context/methods.rb +16 -5
  41. data/lib/rio/context/skip.rb +3 -4
  42. data/lib/rio/context/stream.rb +42 -5
  43. data/lib/rio/cp.rb +7 -7
  44. data/lib/rio/def.rb +3 -4
  45. data/lib/rio/dir.rb +3 -4
  46. data/lib/rio/doc.rb +4 -5
  47. data/lib/rio/doc/EXAMPLES.rb +299 -0
  48. data/lib/rio/doc/HOWTO.rb +3 -4
  49. data/lib/rio/doc/INTRO.rb +86 -105
  50. data/lib/rio/doc/OPTIONAL.rb +4 -5
  51. data/lib/rio/doc/SYNOPSIS.rb +7 -6
  52. data/lib/rio/entrysel.rb +21 -23
  53. data/lib/rio/exception.rb +3 -4
  54. data/lib/rio/exception/copy.rb +3 -4
  55. data/lib/rio/exception/notimplemented.rb +57 -0
  56. data/lib/rio/exception/notsupported.rb +3 -4
  57. data/lib/rio/exception/open.rb +3 -4
  58. data/lib/rio/exception/state.rb +3 -4
  59. data/lib/rio/ext.rb +47 -13
  60. data/lib/rio/ext/csv.rb +4 -5
  61. data/lib/rio/ext/if.rb +45 -0
  62. data/lib/rio/ext/mp3info.rb +80 -0
  63. data/lib/rio/ext/splitlines.rb +253 -0
  64. data/lib/rio/ext/yaml.rb +9 -5
  65. data/lib/rio/ext/yaml/doc.rb +133 -0
  66. data/lib/rio/ext/yaml/tie.rb +149 -0
  67. data/lib/rio/ext/zipfile.rb +23 -4
  68. data/lib/rio/ext/zipfile/fs.rb +116 -0
  69. data/lib/rio/ext/zipfile/rl.rb +251 -0
  70. data/lib/rio/ext/zipfile/rootdir.rb +117 -0
  71. data/lib/rio/ext/zipfile/state.rb +161 -0
  72. data/lib/rio/ext/zipfile/wrap.rb +204 -0
  73. data/lib/rio/factory.rb +235 -27
  74. data/lib/rio/file.rb +4 -4
  75. data/lib/rio/filter.rb +3 -4
  76. data/lib/rio/filter/closeoneof.rb +3 -4
  77. data/lib/rio/filter/gzip.rb +9 -4
  78. data/lib/rio/fs/base.rb +3 -4
  79. data/lib/rio/fs/impl.rb +4 -5
  80. data/lib/rio/fs/native.rb +3 -4
  81. data/lib/rio/fs/stream.rb +3 -4
  82. data/lib/rio/fs/url.rb +3 -4
  83. data/lib/rio/ftp/conncache.rb +19 -5
  84. data/lib/rio/ftp/dir.rb +3 -4
  85. data/lib/rio/ftp/fs.rb +30 -24
  86. data/lib/rio/grande.rb +27 -7
  87. data/lib/rio/handle.rb +3 -4
  88. data/lib/rio/if.rb +19 -15
  89. data/lib/rio/if/basic.rb +7 -7
  90. data/lib/rio/if/csv.rb +5 -6
  91. data/lib/rio/if/dir.rb +120 -114
  92. data/lib/rio/if/file.rb +52 -44
  93. data/lib/rio/if/fileordir.rb +217 -211
  94. data/lib/rio/if/grande.rb +674 -644
  95. data/lib/rio/if/grande_entry.rb +321 -313
  96. data/lib/rio/if/grande_stream.rb +653 -553
  97. data/lib/rio/if/internal.rb +3 -4
  98. data/lib/rio/if/path.rb +425 -426
  99. data/lib/rio/if/rubyio.rb +681 -0
  100. data/lib/rio/if/string.rb +42 -5
  101. data/lib/rio/if/temp.rb +3 -4
  102. data/lib/rio/if/test.rb +245 -238
  103. data/lib/rio/if/yaml.rb +15 -41
  104. data/lib/rio/ioh.rb +7 -5
  105. data/lib/rio/iomode.rb +19 -7
  106. data/lib/rio/ios/fail.rb +4 -5
  107. data/lib/rio/ios/generic.rb +4 -5
  108. data/lib/rio/ios/mode.rb +4 -5
  109. data/lib/rio/ios/null.rb +6 -7
  110. data/lib/rio/iowrap.rb +3 -4
  111. data/lib/rio/kernel.rb +3 -5
  112. data/lib/rio/local.rb +3 -4
  113. data/lib/rio/match.rb +3 -4
  114. data/lib/rio/matchrecord.rb +3 -4
  115. data/lib/rio/no_warn.rb +3 -4
  116. data/lib/rio/nullio.rb +3 -4
  117. data/lib/rio/open3.rb +4 -5
  118. data/lib/rio/ops/construct.rb +3 -4
  119. data/lib/rio/ops/create.rb +11 -6
  120. data/lib/rio/ops/dir.rb +19 -8
  121. data/lib/rio/ops/either.rb +6 -5
  122. data/lib/rio/ops/file.rb +3 -4
  123. data/lib/rio/ops/path.rb +14 -35
  124. data/lib/rio/ops/stream.rb +3 -4
  125. data/lib/rio/ops/stream/input.rb +4 -7
  126. data/lib/rio/ops/stream/output.rb +3 -4
  127. data/lib/rio/ops/stream/read.rb +6 -5
  128. data/lib/rio/ops/stream/write.rb +3 -4
  129. data/lib/rio/ops/symlink.rb +3 -4
  130. data/lib/rio/path.rb +22 -18
  131. data/lib/rio/path/reset.rb +4 -5
  132. data/lib/rio/piper.rb +3 -4
  133. data/lib/rio/piper/cp.rb +3 -4
  134. data/lib/rio/prompt.rb +10 -5
  135. data/lib/rio/rectype.rb +5 -5
  136. data/lib/rio/rl/base.rb +17 -71
  137. data/lib/rio/rl/builder.rb +14 -38
  138. data/lib/rio/rl/chmap.rb +66 -0
  139. data/lib/rio/rl/fs2url.rb +82 -0
  140. data/lib/rio/rl/ioi.rb +4 -4
  141. data/lib/rio/rl/path.rb +44 -122
  142. data/lib/rio/rl/pathmethods.rb +19 -8
  143. data/lib/rio/rl/uri.rb +137 -60
  144. data/lib/rio/rl/withpath.rb +295 -0
  145. data/lib/rio/scheme/aryio.rb +3 -4
  146. data/lib/rio/scheme/cmdio.rb +3 -4
  147. data/lib/rio/scheme/cmdpipe.rb +4 -4
  148. data/lib/rio/scheme/fd.rb +3 -4
  149. data/lib/rio/scheme/ftp.rb +7 -7
  150. data/lib/rio/scheme/http.rb +4 -5
  151. data/lib/rio/scheme/null.rb +3 -4
  152. data/lib/rio/scheme/path.rb +3 -4
  153. data/lib/rio/scheme/stderr.rb +3 -4
  154. data/lib/rio/scheme/stdio.rb +3 -4
  155. data/lib/rio/scheme/strio.rb +3 -4
  156. data/lib/rio/scheme/sysio.rb +3 -4
  157. data/lib/rio/scheme/tcp.rb +3 -4
  158. data/lib/rio/scheme/temp.rb +6 -6
  159. data/lib/rio/state.rb +18 -46
  160. data/lib/rio/state/error.rb +3 -4
  161. data/lib/rio/stream.rb +4 -4
  162. data/lib/rio/stream/base.rb +3 -4
  163. data/lib/rio/stream/duplex.rb +3 -4
  164. data/lib/rio/stream/open.rb +3 -8
  165. data/lib/rio/symantics.rb +3 -4
  166. data/lib/rio/tempdir.rb +2 -2
  167. data/lib/rio/to_rio.rb +3 -4
  168. data/lib/rio/to_rio/all.rb +3 -4
  169. data/lib/rio/to_rio/array.rb +4 -5
  170. data/lib/rio/to_rio/io.rb +4 -5
  171. data/lib/rio/to_rio/object.rb +4 -5
  172. data/lib/rio/to_rio/string.rb +4 -5
  173. data/lib/rio/uri/file.rb +41 -5
  174. data/lib/rio/util.rb +3 -4
  175. data/lib/rio/version.rb +4 -5
  176. data/setup.rb +368 -339
  177. data/test/bin/list_dir.rb +1 -1
  178. data/test/ftp/anon_misc.rb +13 -1
  179. data/test/ftp/anon_special.rb +6 -6
  180. data/test/ftp/anon_write.rb +10 -3
  181. data/test/ftp/ftp2ftp.rb +2 -2
  182. data/test/ftp/testdef.rb +9 -6
  183. data/test/http/all.rb +3 -0
  184. data/test/http/copy-from-http.rb +140 -0
  185. data/test/lib/temp_server.rb +44 -0
  186. data/test/runalltests.rb +3 -1
  187. data/test/runhttp.rb +12 -0
  188. data/test/runhttptests.rb +1 -1
  189. data/test/runtests.rb +41 -3
  190. data/test/tc/abs.rb +9 -5
  191. data/test/tc/all.rb +9 -4
  192. data/test/tc/base.rb +1 -1
  193. data/test/tc/base2.rb +87 -0
  194. data/test/tc/{methods.rb → clone.rb} +72 -50
  195. data/test/tc/closeoncopy.rb +13 -2
  196. data/test/tc/copy-dir-samevar.rb +91 -0
  197. data/test/tc/dir_iter.rb +0 -1
  198. data/test/tc/empty.rb +6 -2
  199. data/test/tc/expand_path.rb +36 -54
  200. data/test/tc/ext.rb +42 -18
  201. data/test/tc/gzip.rb +30 -3
  202. data/test/tc/likeio.rb +5 -1
  203. data/test/tc/line_record_row.rb +51 -0
  204. data/test/tc/noqae.rb +71 -70
  205. data/test/tc/path_parts.rb +175 -0
  206. data/test/tc/programs_util.rb +3 -3
  207. data/test/tc/rename.rb +4 -5
  208. data/test/tc/riorl.rb +9 -7
  209. data/test/tc/skip.rb +35 -6
  210. data/test/tc/skiplines.rb +34 -5
  211. data/test/tc/split.rb +8 -50
  212. data/test/tc/splitlines.rb +65 -0
  213. data/test/tc/splitpath.rb +83 -0
  214. data/test/tc/testcase.rb +1 -1
  215. data/test/tc/truncate.rb +39 -0
  216. data/test/tc/yaml.rb +9 -8
  217. metadata +261 -207
  218. data/ChangeLog +0 -1418
  219. data/VERSION +0 -1
  220. data/lib/rio/doc/MISC.rb +0 -259
  221. data/lib/rio/if/stream.rb +0 -680
  222. data/lib/rio/impl/path.rb +0 -87
  223. data/test/tc/copy-from-http.rb +0 -89
@@ -0,0 +1,681 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005,2006,2007 Christopher Kleckner
4
+ # All rights reserved
5
+ #
6
+ # This file is part of the Rio library for ruby.
7
+ #
8
+ # Rio is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # Rio is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with Rio; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ # ===============================================================================
22
+ #++
23
+ #
24
+ # To create the documentation for Rio run the command
25
+ # ruby build_doc.rb
26
+ # from the distribution directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Doc::EXAMPLES
33
+ # * RIO::Rio
34
+ #
35
+
36
+
37
+ module RIO
38
+ module IF
39
+ module RubyIO
40
+ # Calls IO#gets
41
+ #
42
+ # Reads the next line from the Rio; lines are separated by sep_string.
43
+ # A separator of nil reads the entire contents, and a zero-length separator reads
44
+ # the input a paragraph at a time (two successive newlines in the input separate paragraphs).
45
+ #
46
+ # Returns nil if called at end of file.
47
+ #
48
+ # astring = rio('afile.txt').gets # read the first line of afile.txt into astring
49
+ #
50
+ def gets(sep_string=$/) target.gets(sep_string) end
51
+
52
+ # IF::Grande#each_record
53
+ #
54
+ #
55
+ #def each_record(&block) target.each_record(&block); self end
56
+
57
+
58
+ # IF::Grande#each_row
59
+ #
60
+ #
61
+ #def each_row(&block) target.each_row(&block); self end
62
+
63
+
64
+ # Calls IO#lineno
65
+ #
66
+ # Returns the current line number of a Rio.
67
+ #
68
+ # The Rio will be opened for reading if not already.
69
+ # lineno counts the number of times gets is called, rather than the number of newlines encountered --
70
+ # so lineno will only be accurate if the file is read exclusively with line-oriented methods
71
+ # (IF::RubyIO#readline, IF::Grande#each_line, IF::RubyIO#gets etc.)
72
+ #
73
+ # See also the $. variable and IF::RubyIO#recno
74
+ # f = rio("testfile")
75
+ # f.lineno #=> 0
76
+ # f.gets #=> "This is line one\n"
77
+ # f.lineno #=> 1
78
+ # f.gets #=> "This is line two\n"
79
+ # f.lineno #=> 2
80
+ def lineno() target.lineno() end
81
+
82
+ # Calls IO#lineno=
83
+ # ario.lineno = integer => integer
84
+ # Manually sets the current line number to the given value. <tt>$.</tt> is
85
+ # updated only on the next read.
86
+ #
87
+ # f = rio("testfile")
88
+ # f.gets #=> "This is line one\n"
89
+ # $. #=> 1
90
+ # f.lineno = 1000
91
+ # f.lineno #=> 1000
92
+ # $. # lineno of last read #=> 1
93
+ # f.gets #=> "This is line two\n"
94
+ # $. # lineno of last read #=> 1001
95
+ #
96
+ #
97
+ def lineno=(integer) target.lineno = integer end
98
+
99
+ # Returns the current record number of a Rio. The +recno+ is the index
100
+ # used by the grande selection methods. It represents the zero-based index of the
101
+ # last record read. Returns nil until a record has been read.
102
+ #
103
+ # see IF::GrandeStream#lines IF::GrandeStream#bytes and IF::GrandeStream#records
104
+ #
105
+ # To illustrate: Given a file containing three lines "L0\n","L1\n","L2\n"
106
+ # and a Range (0..1)
107
+ # Each of the following would fill anarray with ["L0\n", "L1\n"]
108
+ #
109
+ # Given:
110
+ # anarray = []
111
+ # range = (0..1)
112
+ #
113
+ # all_lines = rio('afile').readlines
114
+ # all_lines.each_with_index do |line,i|
115
+ # anarray << line if range === i
116
+ # end
117
+ # # anarray == ["L0\n", "L1\n"]
118
+ #
119
+ # anarray = rio('afile').lines[0..1] # anarray == ["L0\n", "L1\n"]
120
+ #
121
+ # +recno+ counts the number of times IF::Grande#getrec or IF::Grande#each is used to get a record.
122
+ # so +recno+ will only concern parts of the file read with grande methods
123
+ # IF::Grande#each, IF::Grande#[], IF::Grande#getrec
124
+ #
125
+ # See also IF::RubyIO#lineno
126
+ def recno() target.recno() end
127
+
128
+
129
+ # Calls IO#binmode
130
+ #
131
+ # Puts rio into binary mode. This is useful only in MS-DOS/Windows environments.
132
+ # Once a stream is in binary mode, it cannot be reset to nonbinary mode.
133
+ #
134
+ # Returns the Rio.
135
+ #
136
+ # rio('afile.exe').binmode.bytes(512).to_a # read a file in 512 byte blocks
137
+ #
138
+ def binmode() target.binmode(); self end
139
+
140
+
141
+ # Calls IO#flush
142
+ # ario.flush => ario
143
+ # Flushes any buffered data within _ario_ to the underlying operating
144
+ # system (note that this is Ruby internal buffering only; the OS may
145
+ # buffer the data as well).
146
+ #
147
+ def flush() target.flush(); self end
148
+
149
+
150
+ # Calls IO#each_byte
151
+ # ario.each_byte {|byte| block } => ario
152
+ # Calls the given block once for each byte (0..255) in _ario_, passing
153
+ # the byte as an argument.
154
+ #
155
+ def each_byte(*args,&block) target.each_byte(*args,&block); self end
156
+
157
+
158
+ # IF::RubyIO#each_bytes
159
+ #
160
+ #
161
+ #def each_bytes(nb,*args,&block) target.each_bytes(nb,*args,&block); self end
162
+
163
+
164
+ # Calls IO#each_line
165
+ # ario.each_line(sep_string=$/) {|line| block } => ario
166
+ # Executes the block for every line in _ario_, where lines are
167
+ # separated by _sep_string_.
168
+ #
169
+ def each_line(*args,&block) target.each_line(*args,&block); self end
170
+
171
+
172
+ # Calls IO#readlines
173
+ #
174
+ # Reads all of the lines in a Rio, and returns them in anArray.
175
+ # Lines are separated by the optional aSepString.
176
+ # The stream must be opened for reading or an IOerror will be raised.
177
+ #
178
+ # an_array = rio('afile.txt').readlines # read afile.txt into an array
179
+ # an_array = rio('afile.txt').chomp.readlines # read afile.txt into an array with each line chomped
180
+ #
181
+ def readlines(*args,&block) target.readlines(*args,&block) end
182
+
183
+ # Calls IO#readline
184
+ # ario.readline(sep_string=$/) => string
185
+ # Reads a line as with +IO#gets+, but raises an +EOFError+ on end of
186
+ # file.
187
+ #
188
+ def readline(*args) target.readline(*args) end
189
+
190
+
191
+ # Calls IO#readpartial
192
+ #
193
+ # Reads at most maxlen bytes from the I/O stream but it blocks
194
+ # only if ios has no data immediately available. If the optional
195
+ # outbuf argument is present, it must reference a String, which
196
+ # will receive the data. It raises EOFError on end of file.
197
+ #
198
+ # readpartial is designed for streams such as pipe, socket, tty, etc. It
199
+ # blocks only when no data immediately available. This means that it
200
+ # blocks only when following all conditions hold.
201
+ #
202
+ # * the buffer in the IO object is empty.
203
+ # * the content of the stream is empty.
204
+ # * the stream is not reached to EOF.
205
+ #
206
+ # When readpartial blocks, it waits data or EOF on the stream. If some
207
+ # data is reached, readpartial returns with the data. If EOF is reached,
208
+ # readpartial raises EOFError.
209
+ #
210
+ # When readpartial doesn�t blocks, it returns or raises immediately. If
211
+ # the buffer is not empty, it returns the data in the buffer. Otherwise
212
+ # if the stream has some content, it returns the data in the
213
+ # stream. Otherwise if the stream is reached to EOF, it raises EOFError.
214
+ #
215
+ # r, w = IO.pipe # buffer pipe content
216
+ # w << "abc" # "" "abc".
217
+ # r.readpartial(4096) #=> "abc" "" ""
218
+ # r.readpartial(4096) # blocks because buffer and pipe is empty.
219
+ #
220
+ # r, w = IO.pipe # buffer pipe content
221
+ # w << "abc" # "" "abc"
222
+ # w.close # "" "abc" EOF
223
+ # r.readpartial(4096) #=> "abc" "" EOF
224
+ # r.readpartial(4096) # raises EOFError
225
+ #
226
+ # r, w = IO.pipe # buffer pipe content
227
+ # w << "abc\ndef\n" # "" "abc\ndef\n"
228
+ # r.gets #=> "abc\n" "def\n" ""
229
+ # w << "ghi\n" # "def\n" "ghi\n"
230
+ # r.readpartial(4096) #=> "def\n" "" "ghi\n"
231
+ # r.readpartial(4096) #=> "ghi\n" "" ""
232
+ #
233
+ # Note that readpartial is nonblocking-flag insensitive. It blocks even
234
+ # if the nonblocking-flag is set.
235
+ #
236
+ # Also note that readpartial behaves similar to sysread in blocking
237
+ # mode. The behavior is identical when the buffer is empty.
238
+ # ios.reopen(other_IO) => ios ios.reopen(path, mode_str) => ios
239
+ #
240
+ # Reassociates ios with the I/O stream given in other_IO or to a new
241
+ # stream opened on path. This may dynamically change the actual class of
242
+ # this stream.
243
+ #
244
+ # f1 = File.new("testfile")
245
+ # f2 = File.new("testfile")
246
+ # f2.readlines[0] #=> "This is line one\n"
247
+ # f2.reopen(f1) #=> #<File:testfile>
248
+ # f2.readlines[0] #=> "This is line one\n"
249
+ #
250
+ def readpartial(*args) target.readpartial(*args) end
251
+
252
+
253
+ # Calls IO::print
254
+ #
255
+ # Writes the given object(s) to the Rio. If the output record separator ($\) is not nil,
256
+ # it will be appended to the output. If no arguments are given, prints $_.
257
+ # Objects that aren't strings will be converted by calling their to_s method.
258
+ # Returns the Rio.
259
+ #
260
+ # rio('f.txt').print("Hello Rio\n") # print the string to f.txt
261
+ # rio(?-).print("Hello Rio\n") # print the string to stdout
262
+ #
263
+ def print(*args,&block) target.print(*args,&block); self end
264
+
265
+ # Writes the given objects to the rio as with IF::RubyIO#print and then closes the Rio.
266
+ # Returns the Rio.
267
+ #
268
+ # Equivalent to rio.print(*args).close
269
+ #
270
+ # rio('f.txt').print!("Hello Rio\n") # print the string to f.txt then close it
271
+ #
272
+ def print!(*args,&block) target.print!(*args,&block); self end
273
+
274
+
275
+ # Writes the given objects to the rio as with IF::RubyIO#printf and then closes the rio.
276
+ # Returns the rio.
277
+ #
278
+ # Equivalent to rio.printf(*args).close
279
+ #
280
+ def printf!(*argv) target.printf!(*argv); self end
281
+
282
+
283
+ # Calls IO#printf
284
+ # ario.printf(format_string [, obj, ...] ) => ario
285
+ # Formats and writes to _ario_, converting parameters under control of
286
+ # the format string. See +Kernel#sprintf+ for details.
287
+ #
288
+ def printf(*argv) target.printf(*argv); self end
289
+
290
+
291
+ # Writes the given objects to the rio as with IF::RubyIO#putc and then closes the rio.
292
+ # Returns the rio.
293
+ #
294
+ # Equivalent to rio.putc(*args).close
295
+ #
296
+ def putc!(*argv) target.putc!(*argv); self end
297
+
298
+
299
+ # Calls IO#putc
300
+ # ario.putc(obj) => ario
301
+ # If _obj_ is +Numeric+, write the character whose code is _obj_,
302
+ # otherwise write the first character of the string representation of
303
+ # _obj_ to _ario_.
304
+ #
305
+ # stdout = rio(?-)
306
+ # stdout.putc "A"
307
+ # stdout.putc 65
308
+ #
309
+ # _produces:_
310
+ #
311
+ # AA
312
+ #
313
+ def putc(*argv) target.putc(*argv); self end
314
+
315
+
316
+ # Calls IO#puts
317
+ #
318
+ # Writes the given objects to the rio as with IF::RubyIO#print.
319
+ # Writes a record separator (typically a newline) after any that do not already end with a newline sequence.
320
+ # If called with an array argument, writes each element on a new line.
321
+ # If called without arguments, outputs a single record separator.
322
+ # Returns the rio.
323
+ def puts(*args) target.puts(*args); self end
324
+
325
+ # Writes the given objects to the rio as with IF::RubyIO#puts and then closes the rio.
326
+ # Returns the rio.
327
+ #
328
+ # Equivalent to rio.puts(*args).close
329
+ #
330
+ # rio('f.txt').puts!('Hello Rio') # print the string to f.txt then close it
331
+ #
332
+ def puts!(*args) target.puts!(*args); self end
333
+
334
+
335
+ # Writes the given objects to the rio as with IF::RubyIO#write and then closes the rio.
336
+ #
337
+ # Equivalent to
338
+ # ario.write(*args)
339
+ # ario.close
340
+ #
341
+ def write!(*argv) target.write!(*argv) end
342
+
343
+
344
+ # Calls IO#write
345
+ # ario.write(string) => integer
346
+ # Writes the given string to _ario_. If the argument is not a string,
347
+ # it will be converted to a
348
+ # string using +to_s+. Returns the number of bytes written.
349
+ #
350
+ def write(*argv) target.write(*argv) end
351
+
352
+
353
+ # Calls IO#eof?
354
+ # ario.eof => true or false
355
+ # Returns true if _ario_ is at end of file. The stream must be opened
356
+ # for reading or an +IOError+ will be raised.
357
+ #
358
+ def eof?() target.eof? end
359
+
360
+ # Provides direct access to the IO handle (as would be returned by ::IO#new) *with* filtering.
361
+ # Reading from and writing to this handle will be affected
362
+ # by such things as IF::GrandeStream#gzip and IF::GrandeStream#chomp if they were specified for the Rio.
363
+ #
364
+ # Compare this with IF::RubyIO#ios
365
+ #
366
+ def ioh(*args) target.ioh() end
367
+
368
+ # Provides direct access to the IO handle (as would be returned by ::IO#new)
369
+ # Reading from and writing to this handle
370
+ # is *not* affected by such things as IF::GrandeStream#gzip and IF::GrandeStream#chomp.
371
+ #
372
+ # Compare this with IF::RubyIO#ioh
373
+ #
374
+ def ios(*args) target.ios() end
375
+
376
+ #def open(m,*args) target.open(m,*args); self end
377
+
378
+ # Explicitly set the mode with which a Rio will be opened.
379
+ # ario.mode('r+') => ario
380
+ # Normally one needs never open a Rio or specify its mode -- the mode is determined by the
381
+ # operation the Rio is asked to perform. (i.e. IF::RubyIO#print requires write access, IF::RubyIO#readlines requires
382
+ # read access). However there are times when one wishes to be specific about the mode with which a Rio
383
+ # will be opened. Note that explicitly setting the mode overrides all of Rio's internal mode
384
+ # logic. If a mode is specified via IF::RubyIO#mode or IF::FileOrDir#open that mode will be used. Period.
385
+ #
386
+ # Returns the Rio.
387
+ #
388
+ # See also IF::RubyIO#mode?
389
+ #
390
+ # If the mode is given as a String, it must be one of the values listed in the following table.
391
+ #
392
+ # Mode | Meaning
393
+ # -----+--------------------------------------------------------
394
+ # "r" | Read-only, starts at beginning of file (default mode).
395
+ # -----+--------------------------------------------------------
396
+ # "r+" | Read-write, starts at beginning of file.
397
+ # -----+--------------------------------------------------------
398
+ # "w" | Write-only, truncates existing file
399
+ # | to zero length or creates a new file for writing.
400
+ # -----+--------------------------------------------------------
401
+ # "w+" | Read-write, truncates existing file to zero length
402
+ # | or creates a new file for reading and writing.
403
+ # -----+--------------------------------------------------------
404
+ # "a" | Write-only, starts at end of file if file exists,
405
+ # | otherwise creates a new file for writing.
406
+ # -----+--------------------------------------------------------
407
+ # "a+" | Read-write, starts at end of file if file exists,
408
+ # | otherwise creates a new file for reading and
409
+ # | writing.
410
+ # -----+--------------------------------------------------------
411
+ # "b" | (DOS/Windows only) Binary file mode (may appear with
412
+ # | any of the key letters listed above).
413
+ #
414
+ # ario = rio('afile').mode('r+').nocloseoneof # file will be opened in r+ mode
415
+ # # don't want the file closed at eof
416
+ # ario.seek(apos).gets # read the string at apos in afile
417
+ # ario.rewind.gets # read the string at the beginning of the file
418
+ # ario.close
419
+ #
420
+ # TODO:
421
+ # * Add support for integer modes
422
+ #
423
+ def mode(m,*args) target.mode(m,*args); self end
424
+
425
+ # Query a Rio's mode
426
+ # ario.mode? #=> a mode string
427
+ #
428
+ # See IF::RubyIO#mode
429
+ #
430
+ # ario = rio('afile')
431
+ # ario.puts("Hello World")
432
+ # ario.mode? #=> 'w' IF::RubyIO#puts requires write access
433
+ #
434
+ # ario = rio('afile')
435
+ # ario.gets
436
+ # ario.mode? #=> 'r' IF::RubyIO#gets requires read access
437
+ #
438
+ # ario = rio('afile').mode('w+').nocloseoneof
439
+ # ario.gets
440
+ # ario.mode? #=> 'w+' Set explictly
441
+ #
442
+ def mode?() target.mode?() end
443
+
444
+
445
+
446
+ # Calls IO#close
447
+ # ario.close => nil
448
+ # Closes _ario_ and flushes any pending writes to the operating
449
+ # system. The stream is unavailable for any further data operations;
450
+ # an +IOError+ is raised if such an attempt is made. I/O streams are
451
+ # automatically closed when they are claimed by the garbage
452
+ # collector.
453
+ #
454
+ def close() target.close(); self end
455
+ def close_write() target.close_write(); self end
456
+
457
+ # Calls IO#fcntl
458
+ # ario.fcntl(integer_cmd, arg) => integer
459
+ # Provides a mechanism for issuing low-level commands to control or
460
+ # query file-oriented I/O streams. Arguments and results are platform
461
+ # dependent. If _arg_ is a number, its value is passed directly. If
462
+ # it is a string, it is interpreted as a binary sequence of bytes
463
+ # (<tt>Array#pack</tt> might be a useful way to build this string). On Unix
464
+ # platforms, see <tt>fcntl(2)</tt> for details. Not implemented on all
465
+ # platforms.
466
+ #
467
+ #
468
+ def fcntl(integer_cmd,arg) target.fcntl(integer_cmd,arg) end
469
+
470
+ # Calls IO#ioctl
471
+ # ario.ioctl(integer_cmd, arg) => integer
472
+ # Provides a mechanism for issuing low-level commands to control or
473
+ # query I/O devices. Arguments and results are platform dependent. If
474
+ # _arg_ is a number, its value is passed directly. If it is a string,
475
+ # it is interpreted as a binary sequence of bytes. On Unix platforms,
476
+ # see +ioctl(2)+ for details. Not implemented on all platforms.
477
+ #
478
+ #
479
+ def ioctl(integer_cmd,arg) target.ioctl(integer_cmd,arg) end
480
+
481
+ # Calls IO#fileno
482
+ # ario.fileno => fixnum
483
+ # ario.to_i => fixnum
484
+ # Returns an integer representing the numeric file descriptor for
485
+ # _ario_.
486
+ #
487
+ def fileno() target.fileno() end
488
+
489
+
490
+ # Calls IO#fsync
491
+ # ario.fsync => ario
492
+ # Immediately writes all buffered data in _ario_ to disk and
493
+ # return _ario_.
494
+ # Does nothing if the underlying operating system does not support
495
+ # _fsync(2)_. Note that +fsync+ differs from using IF::RubyIO#sync. The
496
+ # latter ensures that data is flushed from Ruby's buffers, but
497
+ # doesn't not guarantee that the underlying operating system actually
498
+ # writes it to disk.
499
+ #
500
+ def fsync() target.fsync end
501
+
502
+ # Calls IO#pid
503
+ # ario.pid => fixnum
504
+ # Returns the process ID of a child process associated with _ario_.
505
+ # This will be set by <tt>IO::popen</tt>.
506
+ #
507
+ # pipe = IO.popen("-")
508
+ # if pipe
509
+ # $stderr.puts "In parent, child pid is #{pipe.pid}"
510
+ # else
511
+ # $stderr.puts "In child, pid is #{$$}"
512
+ # end
513
+ #
514
+ # produces:
515
+ #
516
+ # In child, pid is 26209
517
+ # In parent, child pid is 26209
518
+ #
519
+ #
520
+ def pid() target.pid end
521
+
522
+
523
+ # Calls IO#putc
524
+ # ario.putc(obj) => obj
525
+ # If _obj_ is +Numeric+, write the character whose code is _obj_,
526
+ # otherwise write the first character of the string representation of
527
+ # _obj_ to _ario_.
528
+ #
529
+ # $stdout.putc "A"
530
+ # $stdout.putc 65
531
+ #
532
+ # _produces:_
533
+ #
534
+ # AA
535
+ #
536
+ #
537
+
538
+
539
+ # Calls IO#getc
540
+ # ario.getc => fixnum or nil
541
+ # Gets the next 8-bit byte (0..255) from _ario_. Returns +nil+ if
542
+ # called at end of file.
543
+ #
544
+ # f = File.new("testfile")
545
+ # f.getc #=> 84
546
+ # f.getc #=> 104
547
+ #
548
+ #
549
+ def getc() target.getc() end
550
+
551
+ # Calls IO#readchar
552
+ # ario.readchar => fixnum
553
+ # Reads a character as with +IO#getc+, but raises an +EOFError+ on
554
+ # end of file.
555
+ #
556
+ #
557
+
558
+ # Calls IO#reopen
559
+ # ario.reopen(other_IO) => ios
560
+ # ario.reopen(path, mode_str) => ios
561
+ # Reassociates _ario_ with the I/O stream given in _other_IO_ or to a
562
+ # new stream opened on _path_. This may dynamically change the actual
563
+ # class of this stream.
564
+ #
565
+ # f1 = File.new("testfile")
566
+ # f2 = File.new("testfile")
567
+ # f2.readlines[0] #=> "This is line one\n"
568
+ # f2.reopen(f1) #=> #<File:testfile>
569
+ # f2.readlines[0] #=> "This is line one\n"
570
+ #
571
+ #
572
+ #def reopen(m) target.reopen(m) end
573
+
574
+
575
+ # Calls IO#stat
576
+ # ario.stat => stat
577
+ # Returns status information for _ario_ as an object of type
578
+ # +File::Stat+.
579
+ #
580
+ # f = File.new("testfile")
581
+ # s = f.stat
582
+ # "%o" % s.mode #=> "100644"
583
+ # s.blksize #=> 4096
584
+ # s.atime #=> Wed Apr 09 08:53:54 CDT 2003
585
+ #
586
+ #
587
+
588
+ # Calls IO#to_i
589
+ # to_i()
590
+ # Alias for #fileno
591
+ #
592
+ #
593
+ def to_i() target.to_i() end
594
+
595
+ # Calls IO#to_io
596
+ # ario.to_io -> ios
597
+ # Returns _ario_.
598
+ #
599
+ #
600
+ def to_io() target.to_io() end
601
+
602
+ # Calls IO#tty?
603
+ # ario.tty? => true or false
604
+ # Returns +true+ if _ario_ is associated with a terminal device (tty),
605
+ # +false+ otherwise.
606
+ #
607
+ # rio("testfile").tty? #=> false
608
+ # rio("/dev/tty").tty? #=> true
609
+ #
610
+ #
611
+ def tty?() target.tty?() end
612
+
613
+ # Calls IO#ungetc
614
+ # ario.ungetc(integer) => ario
615
+ # Pushes back one character (passed as a parameter) onto _ario_, such
616
+ # that a subsequent buffered read will return it. Only one character
617
+ # may be pushed back before a subsequent read operation (that is, you
618
+ # will be able to read only the last of several characters that have
619
+ # been pushed back).
620
+ #
621
+ # f = rio("testfile") #=> #<Rio:testfile>
622
+ # c = f.getc #=> 84
623
+ # f.ungetc(c).getc #=> 84
624
+ #
625
+ def ungetc(*args) target.ungetc(*args); self end
626
+
627
+ # Sets the 'sync-mode' of the underlying IO using IO#sync=
628
+ # ario.sync(boolean=true,&block) => ario
629
+ # Sets the Rio so that its 'sync mode' will be set to +true+ or +false+ when opened, or set
630
+ # it immediately if already open. When sync mode is
631
+ # true, all output is immediately flushed to the underlying operating
632
+ # system and is not buffered internally. Returns the rio. See
633
+ # also IF::RubyIO#fsync, IF::RubyIO#nosync, IF::RubyIO#sync?.
634
+ #
635
+ # If a block is given behaves like <tt>ario.sync(arg).each(&block)</tt>
636
+ #
637
+ # f = rio("testfile").sync.puts("Hello World")
638
+ # f.sync? # => true
639
+ #
640
+ def sync(arg=true,&block) target.sync(arg,&block); self end
641
+
642
+ # Similar to IO#sync= false
643
+ # ario.nosync(&block) => ario
644
+ # Sets the Rio so that its 'sync mode' will be set to +false+ when opened, or set
645
+ # it immediately if already open. When sync mode is
646
+ # true, all output is immediately flushed to the underlying operating
647
+ # system and is not buffered internally. Returns the rio. See
648
+ # also IF::RubyIO#fsync, IF::RubyIO#sync, IF::RubyIO#sync?.
649
+ #
650
+ # If a block is given behaves like <tt>ario.nosync.each(&block)</tt>
651
+ #
652
+ # f = rio("testfile").sync.puts("Hello World")
653
+ # f.sync? # => true
654
+ # f.nosync
655
+ # f.sync? # => false
656
+ #
657
+ def nosync(arg=false,&block) target.nosync(arg,&block); self end
658
+
659
+ # Query the current "sync mode" with IO#sync
660
+ # ario.sync? => true or false
661
+ # Returns the current "sync mode" of _ario_. When sync mode is true,
662
+ # all output is immediately flushed to the underlying operating
663
+ # system and is not buffered by Ruby internally. See also IF::RubyIO#fsync,
664
+ # IF::RubyIO#sync, IF::RubyIO#nosync
665
+ #
666
+ # f = rio("testfile")
667
+ # f.sync? #=> false
668
+ #
669
+ def sync?() target.sync?() end
670
+
671
+
672
+
673
+ end
674
+ end
675
+ end
676
+
677
+ module RIO
678
+ class Rio
679
+ include RIO::IF::RubyIO
680
+ end
681
+ end