Class: Protocol::Multipart::FormData::Upload
- Inherits:
-
Object
- Object
- Protocol::Multipart::FormData::Upload
- Includes:
- Readable
- Defined in:
- lib/protocol/multipart/form_data.rb
Overview
A file upload yielded while parsing form data.
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
The submitted filename.
Instance Method Summary collapse
-
#discard ⇒ Object
Consume any unread upload body while applying its limits.
-
#each(chunk_size = 8192) ⇒ Object
Iterate over the upload body.
-
#ended? ⇒ Boolean
Whether the complete upload has been consumed.
-
#headers ⇒ Object
The multipart headers associated with this upload.
-
#initialize(part, filename, size_limit, total_size_limit) ⇒ Upload
constructor
Initialize a streamed file upload.
-
#size ⇒ Object
The number of upload bytes consumed so far.
Methods included from Readable
Constructor Details
#initialize(part, filename, size_limit, total_size_limit) ⇒ Upload
Initialize a streamed file upload.
38 39 40 41 42 43 |
# File 'lib/protocol/multipart/form_data.rb', line 38 def initialize(part, filename, size_limit, total_size_limit) @part = part @filename = filename @size_limit = ByteLimit.new(size_limit, name: :upload_size) @total_size_limit = total_size_limit end |
Instance Attribute Details
#filename ⇒ Object (readonly)
The submitted filename.
46 47 48 |
# File 'lib/protocol/multipart/form_data.rb', line 46 def filename @filename end |
Instance Method Details
#discard ⇒ Object
Consume any unread upload body while applying its limits.
78 79 80 81 |
# File 'lib/protocol/multipart/form_data.rb', line 78 def discard self.each{|chunk|} return nil end |
#each(chunk_size = 8192) ⇒ Object
Iterate over the upload body.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/protocol/multipart/form_data.rb', line 65 def each(chunk_size = 8192) return to_enum(:each, chunk_size) unless block_given? @part.each(chunk_size) do |chunk| @size_limit.consume(chunk.bytesize) @total_size_limit.consume(chunk.bytesize) yield chunk end return self end |
#ended? ⇒ Boolean
Whether the complete upload has been consumed.
59 60 61 |
# File 'lib/protocol/multipart/form_data.rb', line 59 def ended? @part.ended? end |
#headers ⇒ Object
The multipart headers associated with this upload.
49 50 51 |
# File 'lib/protocol/multipart/form_data.rb', line 49 def headers @part.headers end |
#size ⇒ Object
The number of upload bytes consumed so far.
54 55 56 |
# File 'lib/protocol/multipart/form_data.rb', line 54 def size @size_limit.size end |