Class: AWS::S3::S3Object

Inherits:
Object
  • Object
show all
Defined in:
lib/s3cp/utils.rb

Instance Method Summary collapse

Instance Method Details

#read_as_stream(options = nil, &blk) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/s3cp/utils.rb', line 277

def read_as_stream(options = nil, &blk)
  options ||= {}
  size = content_length
  chunk_size = options[:chunk] || DEFAULT_STREAMING_CHUNK_SIZE
  if options[:range_start] || options[:range_end]
    byte_offset = options[:range_start] || 0
    max_offset = options[:range_end] || size
  else
    byte_offset = options[:tail] ? (size - options[:tail]) : 0
    max_offset = options[:head] ? (options[:head] - 1) : size
  end
  $stderr.print "Downloading byte range #{byte_offset}-#{max_offset}\n" if options[:debug]
  while byte_offset < max_offset
    range = "bytes=#{byte_offset}-#{[byte_offset + chunk_size - 1, max_offset].min}"
    $stderr.print range + "\n" if options[:debug]
    yield read(:range => range)
    byte_offset += chunk_size
  end
end