Class: HTTPX::Transcoder::Multipart::Encoder
- Inherits:
-
Object
- Object
- HTTPX::Transcoder::Multipart::Encoder
- Defined in:
- lib/httpx/transcoder/multipart/encoder.rb
Instance Attribute Summary collapse
-
#bytesize ⇒ Object
readonly
Returns the value of attribute bytesize.
Instance Method Summary collapse
- #content_type ⇒ Object
-
#initialize(form) ⇒ Encoder
constructor
A new instance of Encoder.
- #read(length = nil, outbuf = nil) ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(form) ⇒ Encoder
Returns a new instance of Encoder.
8 9 10 11 12 13 14 15 |
# File 'lib/httpx/transcoder/multipart/encoder.rb', line 8 def initialize(form) @boundary = ("-" * 21) << SecureRandom.hex(21) @part_index = 0 @buffer = "".b @form = form @parts = to_parts(form) end |
Instance Attribute Details
#bytesize ⇒ Object (readonly)
Returns the value of attribute bytesize.
6 7 8 |
# File 'lib/httpx/transcoder/multipart/encoder.rb', line 6 def bytesize @bytesize end |
Instance Method Details
#content_type ⇒ Object
17 18 19 |
# File 'lib/httpx/transcoder/multipart/encoder.rb', line 17 def content_type "multipart/form-data; boundary=#{@boundary}" end |
#read(length = nil, outbuf = nil) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/httpx/transcoder/multipart/encoder.rb', line 21 def read(length = nil, outbuf = nil) data = outbuf.clear.force_encoding(Encoding::BINARY) if outbuf data ||= "".b read_chunks(data, length) data unless length && data.empty? end |
#rewind ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/httpx/transcoder/multipart/encoder.rb', line 30 def rewind form = @form.each_with_object([]) do |(key, val), aux| val = val.reopen(val.path, File::RDONLY) if val.is_a?(File) && val.closed? val.rewind if val.respond_to?(:rewind) aux << [key, val] end @form = form @parts = to_parts(form) @part_index = 0 end |