Module | Buffering
In: | openssl/lib/openssl/buffering.rb

### Methods

<< close each each_byte each_line eof eof? flush getc gets new print printf puts read readchar readline readlines readpartial ungetc write

### Included Modules

Enumerable

### Constants

BLOCK_SIZE | = | 1024*16

### Attributes

sync | [RW] |

### Public Class methods

new(*args)

[Source]

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

### Public Instance methods

<<(s)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 196
      def << (s)
        do_write(s)
        self
      end

close()

[Source]

    # File openssl/lib/openssl/buffering.rb, line 235
      def close
        flush rescue nil
        sysclose
      end

each(eol=$/) {|line| ...}

[Source]

    # File openssl/lib/openssl/buffering.rb, line 117
      def each(eol=$/)
        while line = self.gets(eol)
          yield line
        end
      end

each_byte() {|c| ...}

[Source]

    # File openssl/lib/openssl/buffering.rb, line 142
      def each_byte
        while c = getc
          yield(c)
        end
      end

each_line(eol=$/)

Alias for each

eof()

Alias for eof?

eof?()

[Source]

    # File openssl/lib/openssl/buffering.rb, line 157
      def eof?
        fill_rbuff if !@eof && @rbuffer.empty?
        @eof && @rbuffer.empty?
      end

flush()

[Source]

    # File openssl/lib/openssl/buffering.rb, line 228
      def flush
        osync = @sync
        @sync = true
        do_write ""
        @sync = osync
      end

getc()

[Source]

    # File openssl/lib/openssl/buffering.rb, line 137
      def getc
        c = read(1)
        c ? c[0] : nil
      end

gets(eol=$/)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 102
      def gets(eol=$/)
        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
        consume_rbuff(size)
      end

print(*args)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 216
      def print(*args)
        s = ""
        args.each{ |arg| s << arg.to_s }
        do_write(s)
        nil
      end

printf(s, *args)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 223
      def printf(s, *args)
        do_write(s % args)
        nil
      end

puts(*args)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 201
      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)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 56
      def read(size=nil, buf=nil)
        if size == 0
          if buf
            buf.clear
          else
            buf = ""
          end
          return @eof ? nil : buf
        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()

[Source]

    # File openssl/lib/openssl/buffering.rb, line 148
      def readchar
        raise EOFError if eof?
        getc
      end

readline(eol=$/)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 132
      def readline(eol=$/)
        raise EOFError if eof?
        gets(eol)
      end

readlines(eol=$/)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 124
      def readlines(eol=$/)
        ary = []
        while line = self.gets(eol)
          ary << line
        end
        ary
      end

readpartial(maxlen, buf=nil)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 77
      def readpartial(maxlen, buf=nil)
        if maxlen == 0
          if buf
            buf.clear
          else
            buf = ""
          end
          return @eof ? nil : buf
        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)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 153
      def ungetc(c)
        @rbuffer[0,0] = c.chr
      end

write(s)

[Source]

    # File openssl/lib/openssl/buffering.rb, line 191
      def write(s)
        do_write(s)
        s.length
      end

[Validate]