Class: ReactOnRailsPro::RendererHttpClient::MultipartFileBody

Inherits:
Object
  • Object
show all
Defined in:
lib/react_on_rails_pro/renderer_http_client.rb,
sig/react_on_rails_pro/renderer_http_client.rbs

Constant Summary collapse

CHUNK_SIZE =

Returns:

  • (Integer)
64 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ MultipartFileBody

Returns a new instance of MultipartFileBody.

Parameters:

  • body (Object)


113
114
115
116
117
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 113

def initialize(body)
  @body = body
  @io = nil
  @owns_io = false
end

Instance Method Details

#bytesizeInteger?

Returns:

  • (Integer, nil)


129
130
131
132
133
134
135
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 129

def bytesize
  return @body.size if @body.is_a?(Pathname)
  return unless @body.respond_to?(:size)

  position = @body.respond_to?(:pos) ? @body.pos : 0
  @body.size - position
end

#closenil

Returns:

  • (nil)


125
126
127
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 125

def close
  @io&.close if @owns_io && @io && !@io.closed?
end

#readString?

Returns:

  • (String, nil)


119
120
121
122
123
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 119

def read
  io = opened_io
  chunk = io.read(CHUNK_SIZE)
  chunk&.b
end