Method: CloudFiles::StorageObject#data_stream
- Defined in:
- lib/cloudfiles/storage_object.rb
#data_stream(size = -1,, offset = 0, headers = {}, &block) ⇒ Object
Retrieves the data from an object and returns a stream that must be passed to a block. Throws a NoSuchObjectException if the object doesn’t exist.
If the optional size and range arguments are provided, the call will return the number of bytes provided by size, starting from the offset provided in offset.
data = ""
object.data_stream do |chunk|
data += chunk
end
data
=> "This is the text stored in the file"
119 120 121 122 123 124 125 126 127 |
# File 'lib/cloudfiles/storage_object.rb', line 119 def data_stream(size = -1, offset = 0, headers = {}, &block) if size.to_i > 0 range = sprintf("bytes=%d-%d", offset.to_i, (offset.to_i + size.to_i) - 1) headers['Range'] = range end begin SwiftClient.get_object(self.container.connection.storageurl, self.container.connection.authtoken, self.container.escaped_name, (CloudFiles.escape self.name), nil, nil, &block) end end |