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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Downstream.



10
11
12
13
# File 'lib/s3_streamer/downstream.rb', line 10

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

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#eachObject



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

def each
  Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
    http.request get_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