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.



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

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.



13
14
15
# File 'lib/fat_zebra/request/multipart/file_io.rb', line 13

def length
  @length
end

#streamObject (readonly)

Returns the value of attribute stream.



13
14
15
# File 'lib/fat_zebra/request/multipart/file_io.rb', line 13

def stream
  @stream
end

Instance Method Details

#headerObject



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

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