Linux heracles.o2switch.net 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
/
opt
/
alt
/
ruby21
/
share
/
ri
/
2.1.0
/
system
/
IO
/
//opt/alt/ruby21/share/ri/2.1.0/system/IO/read-i.ri
U:RDoc::AnyMethod[iI" read:ETI"IO#read;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"3Reads <i>length</i> bytes from the I/O stream.;To:RDoc::Markup::BlankLine o; ; [I"F<i>length</i> must be a non-negative integer or <code>nil</code>.;T@o; ; [I"-If <i>length</i> is a positive integer, ;TI"Nit try to read <i>length</i> bytes without any conversion (binary mode). ;TI"WIt returns <code>nil</code> or a string whose length is 1 to <i>length</i> bytes. ;TI"5<code>nil</code> means it met EOF at beginning. ;TI"VThe 1 to <i>length</i>-1 bytes string means it met EOF after reading the result. ;TI"?The <i>length</i> bytes string means it doesn't meet EOF. ;TI"7The resulted string is always ASCII-8BIT encoding.;T@o; ; [I"9If <i>length</i> is omitted or is <code>nil</code>, ;TI"@it reads until EOF and the encoding conversion is applied. ;TI"9It returns a string even if EOF is met at beginning.;T@o; ; [I":If <i>length</i> is zero, it returns <code>""</code>.;T@o; ; [ I"JIf the optional <i>outbuf</i> argument is present, it must reference ;TI",a String, which will receive the data. ;TI"QThe <i>outbuf</i> will contain only the received data after the method call ;TI".even if it is not empty at the beginning.;T@o; ; [ I"DAt end of file, it returns <code>nil</code> or <code>""</code> ;TI"depend on <i>length</i>. ;TI"(<code><i>ios</i>.read()</code> and ;TI"@<code><i>ios</i>.read(nil)</code> returns <code>""</code>. ;TI"T<code><i>ios</i>.read(<i>positive-integer</i>)</code> returns <code>nil</code>.;T@o:RDoc::Markup::Verbatim; [I"f = File.new("testfile") ;TI")f.read(16) #=> "This is line one" ;TI" ;TI"# reads whole file ;TI"open("file") {|f| ;TI"H data = f.read # This returns a string even if the file is empty. ;TI" ... ;TI"} ;TI" ;TI"*# iterate over fixed length records. ;TI"$open("fixed-record-file") {|f| ;TI"" while record = f.read(256) ;TI" ... ;TI" end ;TI"} ;TI" ;TI"-# iterate over variable length records. ;TI",# record is prefixed by 32-bit length. ;TI"'open("variable-record-file") {|f| ;TI" while len = f.read(4) ;TI"2 len = len.unpack("N")[0] # 32-bit length ;TI"H record = f.read(len) # This returns a string even if len is 0. ;TI" end ;TI"} ;T:@format0o; ; [I"?Note that this method behaves like fread() function in C. ;TI"nThis means it retry to invoke read(2) system call to read data with the specified length (or until EOF). ;TI"IThis behavior is preserved even if <i>ios</i> is non-blocking mode. ;TI"F(This method is non-blocking flag insensitive as other methods.) ;TI"?If you need the behavior like single read(2) system call, ;TI"5consider readpartial, read_nonblock and sysread.;T: @fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I"@ios.read([length [, outbuf]]) -> string, outbuf, or nil ;T0[ I"(p1 = v1, p2 = v2);T@RFI"IO;TcRDoc::NormalClass00