summaryrefslogtreecommitdiff
path: root/jni/ruby/lib/rubygems/util/stringio.rb
blob: 2ea69617bc214063f1521c4f8b8103454569f1fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Gem::StringSink
  def initialize
    @string = ""
  end

  attr_reader :string

  def write(s)
    @string += s
    s.size
  end

  def set_encoding(enc)
    @string.force_encoding enc
  end
end

class Gem::StringSource
  def initialize(str)
    @string = str.dup
  end

  def read(count=nil)
    if count
      @string.slice!(0,count)
    else
      s = @string
      @string = ""
      s
    end
  end

  alias_method :readpartial, :read
end