Class: S3Streamer::Downstream

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_streamer/downstream.rb

Constant Summary collapse

DEFAULT_PART_SIZE =
10 * 1024 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Downstream

Returns a new instance of Downstream.



8
9
10
11
# File 'lib/s3_streamer/downstream.rb', line 8

def initialize(uri, options={})
  @uri = uri
  @options = options
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/s3_streamer/downstream.rb', line 13

def each
  Net::HTTP.start(@uri.host) do |http|
    http.request(Net::HTTP::Get.new @uri) do |response|
      buffer = BufferedWriter.new(min_part_size: part_size) do |part|
        yield part
      end

      response.read_body { |chunk| buffer.push chunk }

      buffer.finish
    end
  end
end