class HTTPX::Transcoder::Multipart::Encoder

  1. lib/httpx/transcoder/multipart/encoder.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. bytesize
  2. content_type
  3. read
  4. rewind

Attributes

bytesize [R]

Public Class methods

new(form)
[show source]
   # File lib/httpx/transcoder/multipart/encoder.rb
 8 def initialize(form)
 9   @boundary = ("-" * 21) << SecureRandom.hex(21)
10   @part_index = 0
11   @buffer = "".b
12 
13   @form = form
14   @parts = to_parts(form)
15 end

Public Instance methods

content_type()
[show source]
   # File lib/httpx/transcoder/multipart/encoder.rb
17 def content_type
18   "multipart/form-data; boundary=#{@boundary}"
19 end
read(length = nil, outbuf = nil)
[show source]
   # File lib/httpx/transcoder/multipart/encoder.rb
21 def read(length = nil, outbuf = nil)
22   data   = outbuf.clear.force_encoding(Encoding::BINARY) if outbuf
23   data ||= "".b
24 
25   read_chunks(data, length)
26 
27   data unless length && data.empty?
28 end
rewind()
[show source]
   # File lib/httpx/transcoder/multipart/encoder.rb
30 def rewind
31   form = @form.each_with_object([]) do |(key, val), aux|
32     val = val.reopen(val.path, File::RDONLY) if val.is_a?(File) && val.closed?
33     val.rewind if val.respond_to?(:rewind)
34     aux << [key, val]
35   end
36   @form = form
37   @parts = to_parts(form)
38   @part_index = 0
39 end