Method: Rack::Lint::InputWrapper#read
- Defined in:
- lib/rack/lint.rb
#read(*args) ⇒ Object
-
readbehaves like IO#read. Its signature isread([length, [buffer]]).If given,
lengthmust be a non-negative Integer (>= 0) ornil, andbuffermust be a String and may not be nil.If
lengthis given and not nil, then this method reads at mostlengthbytes from the input stream.If
lengthis not given or nil, then this method reads all data until EOF.When EOF is reached, this method returns nil if
lengthis given and not nil, or “” iflengthis not given or is nil.If
bufferis given, then the read data will be placed intobufferinstead of a newly created String object.
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/rack/lint.rb', line 389 def read(*args) assert("rack.input#read called with too many arguments") { args.size <= 2 } if args.size >= 1 assert("rack.input#read called with non-integer and non-nil length") { args.first.kind_of?(Integer) || args.first.nil? } assert("rack.input#read called with a negative length") { args.first.nil? || args.first >= 0 } end if args.size >= 2 assert("rack.input#read called with non-String buffer") { args[1].kind_of?(String) } end v = @input.read(*args) assert("rack.input#read didn't return nil or a String") { v.nil? or v.kind_of? String } if args[0].nil? assert("rack.input#read(nil) returned nil on EOF") { !v.nil? } end v end |