class Upload

Includes
Readable: #copy_to, #save

A file upload yielded while parsing form data.

Definitions

def initialize(part, filename, size_limit, total_size_limit)

Initialize a streamed file upload.

Signature

parameter part Parser::Part

The underlying multipart part.

parameter filename String

The submitted filename.

parameter size_limit Integer | Nil

The upload size limit.

parameter total_size_limit ByteLimit

The shared form-data size limit.

Implementation

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

attr :filename

The submitted filename.

def headers

The multipart headers associated with this upload.

Implementation

def headers
	@part.headers
end

def size

The number of upload bytes consumed so far.

Implementation

def size
	@size_limit.size
end

def ended?

Whether the complete upload has been consumed.

Implementation

def ended?
	@part.ended?
end

def each(chunk_size = 8192)

Iterate over the upload body.

Signature

parameter chunk_size Integer

The maximum chunk size.

Implementation

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

def discard

Consume any unread upload body while applying its limits.

Implementation

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