In Files

  • openssl/lib/openssl/buffering.rb

Class/Module Index [+]

Quicksearch

Buffering

begin

$RCSfile$ – Buffering mix-in module.

Info

'OpenSSL for Ruby 2' project
Copyright (C) 2001 GOTOU YUUZOU <gotoyuzo@notwork.org>
All rights reserved.

Licence

This program is licenced under the same licence as Ruby.
(See the file 'LICENCE'.)

Version

$Id: buffering.rb 14261 2007-12-17 07:06:16Z gotoyuzo $

end

Constants

BLOCK_SIZE

Attributes

sync[RW]

Public Class Methods

new(*args) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 22
def initialize(*args)
  @eof = false
  @rbuffer = ""
  @sync = @io.sync
end
            

Public Instance Methods

<<(s) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 199
def << (s)
  do_write(s)
  self
end
            
close() click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 238
def close
  flush rescue nil
  sysclose
end
            
each(eol=$/) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 120
def each(eol=$/)
  while line = self.gets(eol)
    yield line
  end
end
            
Also aliased as: each_line
each_byte() click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 145
def each_byte
  while c = getc
    yield(c)
  end
end
            
each_line(eol=$/) click to toggle source
Alias for: each
eof() click to toggle source
Alias for: eof?
eof?() click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 160
def eof?
  fill_rbuff if !@eof && @rbuffer.empty?
  @eof && @rbuffer.empty?
end
            
Also aliased as: eof
flush() click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 231
def flush
  osync = @sync
  @sync = true
  do_write ""
  @sync = osync
end
            
getc() click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 140
def getc
  c = read(1)
  c ? c[0] : nil
end
            
gets(eol=$/, limit=nil) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 102
def gets(eol=$/, limit=nil)
  idx = @rbuffer.index(eol)
  until @eof
    break if idx
    fill_rbuff
    idx = @rbuffer.index(eol)
  end
  if eol.is_a?(Regexp)
    size = idx ? idx+$&.size : nil
  else
    size = idx ? idx+eol.size : nil
  end
  if limit and limit >= 0
    size = [size, limit].min
  end
  consume_rbuff(size)
end
            
printf(s, *args) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 226
def printf(s, *args)
  do_write(s % args)
  nil
end
            
puts(*args) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 204
def puts(*args)
  s = ""
  if args.empty?
    s << "\n"
  end
  args.each{|arg|
    s << arg.to_s
    if $/ && /\n\z/ !~ s
      s << "\n"
    end
  }
  do_write(s)
  nil
end
            
read(size=nil, buf=nil) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 56
def read(size=nil, buf=nil)
  if size == 0
    if buf
      buf.clear
      return buf
    else
      return ""
    end
  end
  until @eof
    break if size && size <= @rbuffer.size
    fill_rbuff
  end
  ret = consume_rbuff(size) || ""
  if buf
    buf.replace(ret)
    ret = buf
  end
  (size && ret.empty?) ? nil : ret
end
            
readchar() click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 151
def readchar
  raise EOFError if eof?
  getc
end
            
readline(eol=$/) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 135
def readline(eol=$/)
  raise EOFError if eof?
  gets(eol)
end
            
readlines(eol=$/) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 127
def readlines(eol=$/)
  ary = []
  while line = self.gets(eol)
    ary << line
  end
  ary
end
            
readpartial(maxlen, buf=nil) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 77
def readpartial(maxlen, buf=nil)
  if maxlen == 0
    if buf
      buf.clear
      return buf
    else
      return ""
    end
  end
  if @rbuffer.empty?
    begin
      return sysread(maxlen, buf)
    rescue Errno::EAGAIN
      retry
    end
  end
  ret = consume_rbuff(maxlen)
  if buf
    buf.replace(ret)
    ret = buf
  end
  raise EOFError if ret.empty?
  ret
end
            
ungetc(c) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 156
def ungetc(c)
  @rbuffer[0,0] = c.chr
end
            
write(s) click to toggle source
 
               # File openssl/lib/openssl/buffering.rb, line 194
def write(s)
  do_write(s)
  s.length
end