Class: FatZebra::Request::Multipart::FileIO

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/fat_zebra/request/multipart/file_io.rb

Constant Summary

Constants included from Part

Part::LINE_BREAK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Part

#boundary, #to_io

Constructor Details

#initialize(options) ⇒ FileIO

Returns a new instance of FileIO.



13
14
15
16
17
18
19
20
21
22
# File 'lib/fat_zebra/request/multipart/file_io.rb', line 13

def initialize(options)
  @filename     = options[:filename]
  @file         = options[:file]
  @content_type = options[:content_type]
  @options      = options
  @file_size    = File.size(@file)
  @footer       = LINE_BREAK
  @length       = header.bytesize + @file_size + @footer.length
  @io           = Stream.new(StringIO.new(header), @file, StringIO.new(@footer))
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



11
12
13
# File 'lib/fat_zebra/request/multipart/file_io.rb', line 11

def length
  @length
end

#streamObject (readonly)

Returns the value of attribute stream.



11
12
13
# File 'lib/fat_zebra/request/multipart/file_io.rb', line 11

def stream
  @stream
end

Instance Method Details

#headerObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fat_zebra/request/multipart/file_io.rb', line 24

def header
  part = []
  part << "--#{boundary}"
  part << "Content-Disposition: form-data; name=\"#{@filename}\"; filename=\"#{@filename}\""
  part << "Content-Length: #{@size}"
  part << "Content-Type: #{@content_type}"
  part << 'Content-Transfer-Encoding: binary'
  part << LINE_BREAK

  part.join(LINE_BREAK)
end