Class: Protocol::Multipart::FormData::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/multipart/form_data.rb

Overview

A file upload yielded while parsing form data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(part, filename, maximum_size, total_limit) ⇒ Upload

Initialize a streamed file upload.



35
36
37
38
39
40
# File 'lib/protocol/multipart/form_data.rb', line 35

def initialize(part, filename, maximum_size, total_limit)
	@part = part
	@filename = filename
	@limit = ByteLimit.new(maximum_size, name: :upload_size)
	@total_limit = total_limit
end

Instance Attribute Details

#filenameObject (readonly)

The submitted filename.



43
44
45
# File 'lib/protocol/multipart/form_data.rb', line 43

def filename
  @filename
end

Instance Method Details

#discardObject

Consume any unread upload body while applying its limits.



75
76
77
78
# File 'lib/protocol/multipart/form_data.rb', line 75

def discard
	self.each{|chunk|}
	return nil
end

#each(chunk_size = 8192) ⇒ Object

Iterate over the upload body.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/protocol/multipart/form_data.rb', line 62

def each(chunk_size = 8192)
	return to_enum(:each, chunk_size) unless block_given?
	
	@part.each(chunk_size) do |chunk|
		@limit.consume(chunk.bytesize)
		@total_limit.consume(chunk.bytesize)
		yield chunk
	end
	
	return self
end

#ended?Boolean

Whether the complete upload has been consumed.

Returns:

  • (Boolean)


56
57
58
# File 'lib/protocol/multipart/form_data.rb', line 56

def ended?
	@part.ended?
end

#headersObject

The multipart headers associated with this upload.



46
47
48
# File 'lib/protocol/multipart/form_data.rb', line 46

def headers
	@part.headers
end

#sizeObject

The number of upload bytes consumed so far.



51
52
53
# File 'lib/protocol/multipart/form_data.rb', line 51

def size
	@limit.size
end