Class: Fog::Proxmox::MultipartBody
- Inherits:
-
Object
- Object
- Fog::Proxmox::MultipartBody
- Defined in:
- lib/fog/proxmox/compute/models/multipart_body.rb
Overview
An IO-like multipart body that streams a file between a prefix and suffix.
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #binmode ⇒ Object
-
#initialize(prefix, file, suffix) ⇒ MultipartBody
constructor
A new instance of MultipartBody.
- #read(length = nil, outbuf = nil) ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(prefix, file, suffix) ⇒ MultipartBody
Returns a new instance of MultipartBody.
24 25 26 27 28 29 30 |
# File 'lib/fog/proxmox/compute/models/multipart_body.rb', line 24 def initialize(prefix, file, suffix) @prefix = prefix @file = file @suffix = suffix @size = prefix.bytesize + file_size + suffix.bytesize rewind end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
22 23 24 |
# File 'lib/fog/proxmox/compute/models/multipart_body.rb', line 22 def size @size end |
Instance Method Details
#binmode ⇒ Object
54 55 56 57 |
# File 'lib/fog/proxmox/compute/models/multipart_body.rb', line 54 def binmode @file.binmode if @file.respond_to?(:binmode) self end |
#read(length = nil, outbuf = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/proxmox/compute/models/multipart_body.rb', line 32 def read(length = nil, outbuf = nil) length = @size - @position if length.nil? raise ArgumentError, 'negative length' if length.negative? result = ::String.new(encoding: Encoding::BINARY) read_into(result, length) result = nil if result.empty? && length.positive? && @part > 2 return result unless outbuf outbuf.replace(result || '') result && outbuf end |
#rewind ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/fog/proxmox/compute/models/multipart_body.rb', line 46 def rewind @file.rewind @part = 0 @offset = 0 @position = 0 0 end |