Class: GData::HTTP::MimeBodyString

Inherits:
Object
  • Object
show all
Defined in:
lib/gdata/http/mime_body.rb

Overview

Class makes a string into a stream-like object

Instance Method Summary collapse

Constructor Details

#initialize(source_string) ⇒ MimeBodyString

Returns a new instance of MimeBodyString.



82
83
84
85
# File 'lib/gdata/http/mime_body.rb', line 82

def initialize(source_string)
  @string = source_string
  @bytes_read = 0
end

Instance Method Details

#read(bytes_requested) ⇒ Object

Implement read so that this class can be treated as a stream.



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gdata/http/mime_body.rb', line 92

def read(bytes_requested)
  if @bytes_read == @string.length
    return false
  elsif bytes_requested > @string.length - @bytes_read
    bytes_requested = @string.length - @bytes_read
  end
  
  buffer = @string[@bytes_read, bytes_requested]
  @bytes_read += bytes_requested
  
  return buffer
end

#rewindObject



87
88
89
# File 'lib/gdata/http/mime_body.rb', line 87

def rewind
  @bytes_read = 0
end