@@ -459,6 +459,11 @@ def tty?
459
459
ensure_open
460
460
FFI ::Platform ::POSIX . isatty ( @descriptor ) == 1
461
461
end
462
+
463
+ def inspect
464
+ stat = Stat . fstat ( @descriptor )
465
+ "fd [#{ descriptor } ], mode [#{ @mode } ], total_size [#{ @total_size } ], offset [#{ @offset } ], eof [#{ @eof } ], stat.size [#{ stat . size } ], written? [#{ @written } ]"
466
+ end
462
467
end # class FileDescriptor
463
468
464
469
class BufferedFileDescriptor < FileDescriptor
@@ -700,6 +705,7 @@ def self.select(readables, writables, errorables, timeout)
700
705
701
706
attr_accessor :external
702
707
attr_accessor :internal
708
+ attr_accessor :fd # FIXME: just for debugging
703
709
704
710
def self . binread ( file , length = nil , offset = 0 )
705
711
raise ArgumentError , "Negative length #{ length } given" if !length . nil? && length < 0
@@ -1718,7 +1724,7 @@ def read_to_separator
1718
1724
buffer = "" . force_encoding ( Encoding ::ASCII_8BIT )
1719
1725
separator_size = @separator . bytesize
1720
1726
1721
- until buffer . size == 0 && @io . eof?
1727
+ begin
1722
1728
if buffer . size == 0
1723
1729
buffer = @io . read ( READ_SIZE )
1724
1730
end
@@ -1754,7 +1760,7 @@ def read_to_separator
1754
1760
str << buffer
1755
1761
buffer . clear
1756
1762
end
1757
- end
1763
+ end until buffer . size == 0 && @io . eof?
1758
1764
1759
1765
str << buffer
1760
1766
@@ -1804,7 +1810,7 @@ def read_to_separator_with_limit
1804
1810
#TODO: implement ignoring encoding with negative limit
1805
1811
wanted = limit = @limit . abs
1806
1812
1807
- until buffer . size == 0 && @io . eof?
1813
+ begin
1808
1814
if buffer . size == 0
1809
1815
buffer = @io . read ( READ_SIZE )
1810
1816
end
@@ -1853,7 +1859,7 @@ def read_to_separator_with_limit
1853
1859
buffer . clear
1854
1860
end
1855
1861
end
1856
- end
1862
+ end until buffer . size == 0 && @io . eof?
1857
1863
1858
1864
unless str . empty?
1859
1865
str = IO . read_encode ( @io , str )
@@ -1867,9 +1873,9 @@ def read_to_separator_with_limit
1867
1873
def read_all
1868
1874
str = ""
1869
1875
1870
- until @io . eof?
1876
+ begin
1871
1877
str << @io . read
1872
- end
1878
+ end until @io . eof?
1873
1879
1874
1880
unless str . empty?
1875
1881
str = IO . read_encode ( @io , str )
@@ -1884,7 +1890,7 @@ def read_to_limit
1884
1890
str = ""
1885
1891
wanted = limit = @limit . abs
1886
1892
1887
- until @io . eof?
1893
+ begin
1888
1894
str << @io . read ( wanted )
1889
1895
1890
1896
str = try_to_force_encoding ( @io , str )
@@ -1894,7 +1900,7 @@ def read_to_limit
1894
1900
yield str
1895
1901
1896
1902
str = ""
1897
- end
1903
+ end until @io . eof?
1898
1904
1899
1905
unless str . empty?
1900
1906
str = IO . read_encode ( @io , str )
@@ -2175,15 +2181,15 @@ def getc
2175
2181
return if eof?
2176
2182
2177
2183
char = ""
2178
- until eof?
2184
+ begin
2179
2185
char . force_encoding Encoding ::ASCII_8BIT
2180
2186
char << read ( 1 )
2181
2187
2182
2188
char . force_encoding ( self . external_encoding || Encoding . default_external )
2183
2189
if char . chr_at ( 0 )
2184
2190
return IO . read_encode self , char
2185
2191
end
2186
- end
2192
+ end until eof?
2187
2193
2188
2194
return nil
2189
2195
end
@@ -2409,11 +2415,11 @@ def read(length=nil, buffer=nil)
2409
2415
# If the buffer is already exhausted, returns +""+.
2410
2416
def read_all
2411
2417
str = ""
2412
- until eof?
2418
+ begin
2413
2419
buffer = ""
2414
2420
@fd . read ( nil , buffer )
2415
2421
str << buffer
2416
- end
2422
+ end until eof?
2417
2423
2418
2424
str
2419
2425
end
0 commit comments