| Module | Buffering |
| In: |
openssl/buffering.rb
|
Included Modules
Constants
| BLOCK_SIZE | = | 1024*16 |
Attributes
| sync | [RW] |
Public Class methods
# File openssl/buffering.rb, line 22
22: def initialize(*args)
23: @eof = false
24: @rbuffer = ""
25: @sync = @io.sync
26: end
Public Instance methods
# File openssl/buffering.rb, line 117
117: def each(eol=$/)
118: while line = self.gets(eol)
119: yield line
120: end
121: end
# File openssl/buffering.rb, line 142
142: def each_byte
143: while c = getc
144: yield(c)
145: end
146: end
# File openssl/buffering.rb, line 157
157: def eof?
158: fill_rbuff if !@eof && @rbuffer.empty?
159: @eof && @rbuffer.empty?
160: end
# File openssl/buffering.rb, line 228
228: def flush
229: osync = @sync
230: @sync = true
231: do_write ""
232: @sync = osync
233: end
# File openssl/buffering.rb, line 102
102: def gets(eol=$/)
103: idx = @rbuffer.index(eol)
104: until @eof
105: break if idx
106: fill_rbuff
107: idx = @rbuffer.index(eol)
108: end
109: if eol.is_a?(Regexp)
110: size = idx ? idx+$&.size : nil
111: else
112: size = idx ? idx+eol.size : nil
113: end
114: consume_rbuff(size)
115: end
# File openssl/buffering.rb, line 216
216: def print(*args)
217: s = ""
218: args.each{ |arg| s << arg.to_s }
219: do_write(s)
220: nil
221: end
# File openssl/buffering.rb, line 223
223: def printf(s, *args)
224: do_write(s % args)
225: nil
226: end
# File openssl/buffering.rb, line 201
201: def puts(*args)
202: s = ""
203: if args.empty?
204: s << "\n"
205: end
206: args.each{|arg|
207: s << arg.to_s
208: if $/ && /\n\z/ !~ s
209: s << "\n"
210: end
211: }
212: do_write(s)
213: nil
214: end
# File openssl/buffering.rb, line 56
56: def read(size=nil, buf=nil)
57: if size == 0
58: if buf
59: buf.clear
60: else
61: buf = ""
62: end
63: return @eof ? nil : buf
64: end
65: until @eof
66: break if size && size <= @rbuffer.size
67: fill_rbuff
68: end
69: ret = consume_rbuff(size) || ""
70: if buf
71: buf.replace(ret)
72: ret = buf
73: end
74: (size && ret.empty?) ? nil : ret
75: end
# File openssl/buffering.rb, line 148
148: def readchar
149: raise EOFError if eof?
150: getc
151: end
# File openssl/buffering.rb, line 132
132: def readline(eol=$/)
133: raise EOFError if eof?
134: gets(eol)
135: end
# File openssl/buffering.rb, line 124
124: def readlines(eol=$/)
125: ary = []
126: while line = self.gets(eol)
127: ary << line
128: end
129: ary
130: end
# File openssl/buffering.rb, line 77
77: def readpartial(maxlen, buf=nil)
78: if maxlen == 0
79: if buf
80: buf.clear
81: else
82: buf = ""
83: end
84: return @eof ? nil : buf
85: end
86: if @rbuffer.empty?
87: begin
88: return sysread(maxlen, buf)
89: rescue Errno::EAGAIN
90: retry
91: end
92: end
93: ret = consume_rbuff(maxlen)
94: if buf
95: buf.replace(ret)
96: ret = buf
97: end
98: raise EOFError if ret.empty?
99: ret
100: end