Files: binary-mode and text-mode

The binary-mode or text-mode keywords affect the automatic processing of newlines in the file being read. When you specify the mode binary-mode, no processing is performed on the newlines. When you specify the mode text-mode, the following sequences are translated to a single newline (%10#) character:

  • carriage return followed by a newline ("%13#%10#"),
  • carriage return alone ("%13#"), and
  • newline alone ("%10#").

When neither mode is specified, on a UNIX system, the file is treated as a binary-mode file. (On UNIX systems, the newline (%10#) character is the system-specific newline sequence, so no transformation is necessary for text files.) On all non-UNIX systems, the file is treated as a text-mode file.

Example

The following example opens the file input.txt in text-mode:

  process
     local stream s
  
     open s with (buffered & text-mode) as file "input.txt"
The file input.txt is opened in text-mode and attached to the s; also the file is opened in a buffered mode.

Prerequisite Concepts
Related Topics