Class: FatZebra::Request::Multipart::FileIO
- Inherits:
-
Object
- Object
- FatZebra::Request::Multipart::FileIO
- Includes:
- Part
- Defined in:
- lib/fat_zebra/request/multipart/file_io.rb
Constant Summary
Constants included from Part
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #header ⇒ Object
-
#initialize(options) ⇒ FileIO
constructor
A new instance of FileIO.
Methods included from Part
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() @filename = [:filename] @file = [:file] @content_type = [:content_type] @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
#length ⇒ Object (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 |
#stream ⇒ Object (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
#header ⇒ Object
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 |