Class: Fog::Storage::AWS::Real::S3Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/aws/storage.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, signature, signer, date) ⇒ S3Streamer

Returns a new instance of S3Streamer.



533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/fog/aws/storage.rb', line 533

def initialize(body, signature, signer, date)
  self.body = body
  self.date = date
  self.signature = signature
  self.signer = signer
  if body.respond_to?(:binmode)
    body.binmode
  end
  if body.respond_to?(:pos=)
    body.pos = 0
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



532
533
534
# File 'lib/fog/aws/storage.rb', line 532

def body
  @body
end

#dateObject

Returns the value of attribute date.



532
533
534
# File 'lib/fog/aws/storage.rb', line 532

def date
  @date
end

#finishedObject

Returns the value of attribute finished.



532
533
534
# File 'lib/fog/aws/storage.rb', line 532

def finished
  @finished
end

#signatureObject

Returns the value of attribute signature.



532
533
534
# File 'lib/fog/aws/storage.rb', line 532

def signature
  @signature
end

#signerObject

Returns the value of attribute signer.



532
533
534
# File 'lib/fog/aws/storage.rb', line 532

def signer
  @signer
end

Instance Method Details

#callObject



546
547
548
549
550
551
552
# File 'lib/fog/aws/storage.rb', line 546

def call
  if finished
    ''
  else
    next_chunk
  end
end

#next_chunkObject



554
555
556
557
558
559
560
561
562
# File 'lib/fog/aws/storage.rb', line 554

def next_chunk
  data = body.read(0x10000)
  if data.nil?
    self.finished = true
    data = ''
  end
  self.signature = sign_chunk(data, signature)
  "#{data.length.to_s(16)};chunk-signature=#{signature}\r\n#{data}\r\n"
end

#sign_chunk(data, previous_signature) ⇒ Object



565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/fog/aws/storage.rb', line 565

def sign_chunk(data, previous_signature)
  string_to_sign = <<-DATA
AWS4-HMAC-SHA256-PAYLOAD
#{date.to_iso8601_basic}
#{signer.credential_scope(date)}
#{previous_signature}
#{Digest::SHA256.hexdigest('')}
#{Digest::SHA256.hexdigest(data)}
DATA
  hmac = signer.derived_hmac(date)
  hmac.sign(string_to_sign.strip).unpack('H*').first
end