updating oE read_file


include io.e 
namespace io 
public function read_file(object file, integer as_text = BINARY_MODE) 

reads the contents of a file as a single sequence of bytes.

  1. file : an object, either a file path or the handle to an open file.
  2. as_text : integer, BINARY_MODE (the default) assumes binary mode that causes every byte to be read in, and TEXT_MODE assumes text mode that ensures that lines end with just a Control+J (NewLine) character, and the first byte value of 26 (Control+Z) is interpreted as End-Of-File.

A sequence, holding the entire file.


  • When using BINARY_MODE, each byte in the file is returned as an element in the return sequence.
  • When not using BINARY_MODE, the file will be interpreted as a text file. This means that all line endings will be transformed to a single 0x0A character and the first 0x1A character (Control+Z) will indicate the end of file (all data after this will not be returned to the caller.)
Example 1:
data = read_file("my_file.txt") 
-- data contains the entire contents of ##my_file.txt## 
Example 2:
fh = open("my_file.txt", "r") 
data = read_file(fh) 
-- data contains the entire contents of ##my_file.txt## 
See Also:

write_file, read_lines

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu