Class: Google::Apis::Core::DownloadCommand

Inherits:
ApiCommand show all
Defined in:
lib/google/apis/core/download.rb

Overview

Streaming/resumable media download support

Constant Summary collapse

RANGE_HEADER =
'Range'
OK_STATUS =
[200, 201, 206]

Constants inherited from ApiCommand

ApiCommand::ERROR_REASON_MAPPING, ApiCommand::FIELDS_PARAM, ApiCommand::JSON_CONTENT_TYPE

Constants inherited from HttpCommand

HttpCommand::RETRIABLE_ERRORS

Instance Attribute Summary collapse

Attributes inherited from ApiCommand

#request_object, #request_representation, #response_class, #response_representation

Attributes inherited from HttpCommand

#body, #connection, #header, #method, #options, #params, #query, #url

Instance Method Summary collapse

Methods inherited from ApiCommand

#allow_form_encoding?, #check_status, #decode_response_body

Methods inherited from HttpCommand

#allow_form_encoding?, #apply_request_options, #authorization_refreshable?, #check_status, #decode_response_body, #error, #execute, #initialize, #process_response, #success

Methods included from Logging

#logger

Constructor Details

This class inherits a constructor from Google::Apis::Core::HttpCommand

Instance Attribute Details

#download_destString, ...

File or IO to write content to

Returns:

  • (String, File, #write)


29
30
31
# File 'lib/google/apis/core/download.rb', line 29

def download_dest
  @download_dest
end

Instance Method Details

#prepare!

This method returns an undefined value.

Ensure the download destination is a writable stream.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/google/apis/core/download.rb', line 34

def prepare!
  @state = :start
  @download_url = nil
  @offset = 0
  if download_dest.respond_to?(:write)
    @download_io = download_dest
    @close_io_on_finish = false
  elsif download_dest.is_a?(String)
    @download_io = File.open(download_dest, 'wb')
    @close_io_on_finish = true
  else
    @download_io = StringIO.new('', 'wb')
    @close_io_on_finish = false
  end
  super
end

#release!Object

Close IO stream when command done. Only closes the stream if it was opened by the command.



52
53
54
# File 'lib/google/apis/core/download.rb', line 52

def release!
  @download_io.close if @close_io_on_finish
end