Class: Google::Apis::Core::UploadIO
- Inherits:
-
Hurley::UploadIO
- Object
- Hurley::UploadIO
- Google::Apis::Core::UploadIO
- Defined in:
- lib/google/apis/core/upload.rb
Overview
Extension of Hurley's UploadIO to add length accessor
Constant Summary collapse
- OCTET_STREAM_CONTENT_TYPE =
'application/octet-stream'
Class Method Summary collapse
-
.from_file(file_name, content_type: nil) ⇒ Google::Apis::Core::UploadIO
Create a new instance given a file path.
-
.from_io(io, content_type: OCTET_STREAM_CONTENT_TYPE) ⇒ Google::Apis::Core::UploadIO
Wraps an IO stream in UploadIO.
Instance Method Summary collapse
-
#length ⇒ Fixnum
Get the length of the stream.
Class Method Details
.from_file(file_name, content_type: nil) ⇒ Google::Apis::Core::UploadIO
Create a new instance given a file path
48 49 50 51 52 53 54 |
# File 'lib/google/apis/core/upload.rb', line 48 def self.from_file(file_name, content_type: nil) if content_type.nil? type = MIME::Types.of(file_name) content_type = type.first.content_type unless type.nil? || type.empty? end new(file_name, content_type || OCTET_STREAM_CONTENT_TYPE) end |
.from_io(io, content_type: OCTET_STREAM_CONTENT_TYPE) ⇒ Google::Apis::Core::UploadIO
Wraps an IO stream in UploadIO
62 63 64 |
# File 'lib/google/apis/core/upload.rb', line 62 def self.from_io(io, content_type: OCTET_STREAM_CONTENT_TYPE) new(io, content_type) end |
Instance Method Details
#length ⇒ Fixnum
Get the length of the stream
38 39 40 |
# File 'lib/google/apis/core/upload.rb', line 38 def length io.respond_to?(:length) ? io.length : File.size(local_path) end |