Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
converted until/end into begin/end until which fixed 4 specs
  • Loading branch information
chuckremes committed Sep 29, 2015
1 parent e6e1a08 commit 1805aaa
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions kernel/common/io.rb
Expand Up @@ -459,6 +459,11 @@ def tty?
ensure_open
FFI::Platform::POSIX.isatty(@descriptor) == 1
end

def inspect
stat = Stat.fstat(@descriptor)
"fd [#{descriptor}], mode [#{@mode}], total_size [#{@total_size}], offset [#{@offset}], eof [#{@eof}], stat.size [#{stat.size}], written? [#{@written}]"
end
end # class FileDescriptor

class BufferedFileDescriptor < FileDescriptor
Expand Down Expand Up @@ -700,6 +705,7 @@ def self.select(readables, writables, errorables, timeout)

attr_accessor :external
attr_accessor :internal
attr_accessor :fd # FIXME: just for debugging

def self.binread(file, length=nil, offset=0)
raise ArgumentError, "Negative length #{length} given" if !length.nil? && length < 0
Expand Down Expand Up @@ -1718,7 +1724,7 @@ def read_to_separator
buffer = "".force_encoding(Encoding::ASCII_8BIT)
separator_size = @separator.bytesize

until buffer.size == 0 && @io.eof?
begin
if buffer.size == 0
buffer = @io.read(READ_SIZE)
end
Expand Down Expand Up @@ -1754,7 +1760,7 @@ def read_to_separator
str << buffer
buffer.clear
end
end
end until buffer.size == 0 && @io.eof?

str << buffer

Expand Down Expand Up @@ -1804,7 +1810,7 @@ def read_to_separator_with_limit
#TODO: implement ignoring encoding with negative limit
wanted = limit = @limit.abs

until buffer.size == 0 && @io.eof?
begin
if buffer.size == 0
buffer = @io.read(READ_SIZE)
end
Expand Down Expand Up @@ -1853,7 +1859,7 @@ def read_to_separator_with_limit
buffer.clear
end
end
end
end until buffer.size == 0 && @io.eof?

unless str.empty?
str = IO.read_encode(@io, str)
Expand All @@ -1867,9 +1873,9 @@ def read_to_separator_with_limit
def read_all
str = ""

until @io.eof?
begin
str << @io.read
end
end until @io.eof?

unless str.empty?
str = IO.read_encode(@io, str)
Expand All @@ -1884,7 +1890,7 @@ def read_to_limit
str = ""
wanted = limit = @limit.abs

until @io.eof?
begin
str << @io.read(wanted)

str = try_to_force_encoding(@io, str)
Expand All @@ -1894,7 +1900,7 @@ def read_to_limit
yield str

str = ""
end
end until @io.eof?

unless str.empty?
str = IO.read_encode(@io, str)
Expand Down Expand Up @@ -2175,15 +2181,15 @@ def getc
return if eof?

char = ""
until eof?
begin
char.force_encoding Encoding::ASCII_8BIT
char << read(1)

char.force_encoding(self.external_encoding || Encoding.default_external)
if char.chr_at(0)
return IO.read_encode self, char
end
end
end until eof?

return nil
end
Expand Down Expand Up @@ -2409,11 +2415,11 @@ def read(length=nil, buffer=nil)
# If the buffer is already exhausted, returns +""+.
def read_all
str = ""
until eof?
begin
buffer = ""
@fd.read(nil, buffer)
str << buffer
end
end until eof?

str
end
Expand Down

0 comments on commit 1805aaa

Please sign in to comment.