Class: Hurley::Multipart::FilePart

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/hurley/multipart.rb

Overview

Represents a part to be filled from file IO.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Part

file?, new, #to_io

Constructor Details

#initialize(boundary, name, io, header) ⇒ FilePart



120
121
122
123
124
125
126
127
128
# File 'lib/hurley/multipart.rb', line 120

def initialize(boundary, name, io, header)
  file_length = io.respond_to?(:length) ?  io.length : File.size(io.local_path)

  @head = build_head(boundary, name, io.original_filename, io.content_type, file_length,
                     io.respond_to?(:opts) ? io.opts.merge(header) : header)

  @length = @head.bytesize + file_length + FOOT.length
  @io = CompositeReadIO.new(@length, StringIO.new(@head), io, StringIO.new(FOOT))
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



118
119
120
# File 'lib/hurley/multipart.rb', line 118

def length
  @length
end