Skip to content
Browse files

IO::binread works with offset and length

  • Loading branch information...
1 parent 69e6be7 commit ed54cecfbd3e68523a57ff64b79a9eb7955e2263 Michal Bugno committed Apr 7, 2012
Showing with 6 additions and 9 deletions.
  1. +6 −6 kernel/common/io19.rb
  2. +0 −3 spec/tags/19/ruby/core/io/binread_tags.txt
View
12 kernel/common/io19.rb
@@ -15,13 +15,13 @@ class EAGAINWaitWritable < Errno::EAGAIN
include ::IO::WaitWritable
end
- def self.binread(file, *arg)
- unless arg.size < 3
- raise ArgumentError, "wrong number of arguments (#{1+arg.size} for 1..3)"
- end
+ def self.binread(file, length=nil, offset=0)
+ raise Errno::EINVAL, file if offset < 0
+ raise ArgumentError, "Negative length #{length} given" if !length.nil? && length < 0
- File.open(file,"rb") do |f|
- f.read(*arg)
+ File.open(file, "rb") do |f|
+ f.seek(offset)
+ f.read(length)
end
end
View
3 spec/tags/19/ruby/core/io/binread_tags.txt
@@ -1,3 +0,0 @@
-fails:IO.binread reads the contents of a file from an offset of a specific size when specified
-fails:IO.binread raises an ArgumentError when not passed a valid length
-fails:IO.binread raises an Errno::EINVAL when not passed a valid offset

0 comments on commit ed54cec

Please sign in to comment.
Something went wrong with that request. Please try again.