up: IO     index Zimbu documentation

CLASS IO.File EXTENDS IO.Writer @public

summary

     

File for reading and writing.

Use IO.fileWriter() and IO.fileReader() to create one.

NOTE: this is going to be split up in InputFile and OutputFile.

 
Implements IO.I_ByteReader
Implements IO.I_CharReader
 
C(FILE *)  $fd @directory 
 
$readByte() int @public  Reads and returns one byte. When at end of file returns IO.eof.
$readChar() int @public  Reads one UTF-8 character.
$readAll() string @public  Reads the whole file and returns it as a string.
$readAllBytes() byteString @public  Reads the whole file and returns it as a byteString.
$readAll(size) string @public  Reads the file up to size bytes and returns it as a string.
$readLine() string @public  Reads and returns one line, excluding the terminating NL.
$readLineRaw() string @public  Reads and returns one line, including the terminating NL.
$readAllLines() list<string> @public  Reads the whole file and returns a list with all lines.
$readAllLinesRaw() list<string> @public  Reads the whole file and returns a list with all lines.
$readAllLines(count) list<string> @public  Reads the file and returns a list with up to count lines.
$readAllLinesRaw(count) list<string> @public  Reads the file and returns a list with up to count lines.
$write(text) status @public  Writes text to the file. Returns FAIL or OK.
$writeByte(byte) status @public  Writes byte byte to the file.
$writeAllLines(lines) status @public  Writes lines to the file.
$flush() status @public  Flushes buffered output. Returns FAIL or OK.
$close() status @public  Closes the file, reading/writing will no longer be possible. Returns FAIL when flushing output failed.
$Finish() status @file  Destructor: closes the file if not closed already.
 
Inherited from IO.Writer:
$write(text) status @public  Writes text converted to a string.
$write(number) status @public  Writes number as a decimal number.
$write(number) status @public  Writes number as a decimal number.
$write(number) status @public  Writes number as a decimal number.
$write(flag) status @public  Writes flag as "TRUE" or "FALSE".
$write(ok) status @public  Writes ok as "FAIL" or "OK".
$write(arg) status @public  Writes arg depending on its actual type. Returns FAIL or OK.
$writeChar(char) status @public  Writes char as a UTF-8 byte sequence.
$print(text) status @public  Writes text and appends a newline. Returns FAIL or OK.
$print(number) status @public  Writes number and appends a newline. Returns FAIL or OK.
$print(number) status @public  Writes number and appends a newline. Returns FAIL or OK.
$print(number) status @public  Writes number and appends a newline. Returns FAIL or OK.
$print(flag) status @public  Writes flag as "TRUE" or "FALSE" and appends a newline. Returns FAIL or OK.
$print(ok) status @public  Writes ok as "FAIL" or "OK" and appends a newline. Returns FAIL or OK.
$print(arg) status @public  Writes arg depending on its actual type and appends a newline. Returns FAIL or OK.
$print() status @public  Writes a newline and returns FAIL or OK.
$format(fmt, arguments) status @public  Formats the string and writes it with a newline appended.
 
Known subclasses:
     
 

members (alphabetically)

     

C(FILE *) $fd @directory

FUNC $Finish() status @default @file

     

Destructor: closes the file if not closed already.

FUNC $close() status @default @public

     

Closes the file, reading/writing will no longer be possible. Returns FAIL when flushing output failed.

When called twice the second one will always return FAIL.

FUNC $flush() status @default @public

     

Flushes buffered output. Returns FAIL or OK.

FUNC $readAll() string @public

     

Reads the whole file and returns it as a string.

This is done in binary mode, there are no checks for valid UTF-8 characters.

FUNC $readAll(int size) string @public

     

Reads the file up to size bytes and returns it as a string.

This is done in binary mode, there are no checks for valid UTF-8 characters.

FUNC $readAllBytes() byteString @public

     

Reads the whole file and returns it as a byteString.

This is done in binary mode, there are no checks for valid UTF-8 characters.

FUNC $readAllLines() list<string> @public

     

Reads the whole file and returns a list with all lines.

This is like calling readLine() until reaching end of file.

FUNC $readAllLines(int count) list<string> @public

     

Reads the file and returns a list with up to count lines.

This is like calling readLine() until reaching end of file or reading count lines.

FUNC $readAllLinesRaw() list<string> @public

     

Reads the whole file and returns a list with all lines.

This is like calling readLineRaw() until reaching end of file.

FUNC $readAllLinesRaw(int count) list<string> @public

     

Reads the file and returns a list with up to count lines.

This is like calling readLineRaw() until reaching end of file or reading count lines.

FUNC $readByte() int @default @public

     

Reads and returns one byte. When at end of file returns IO.eof.

FUNC $readChar() int @public

     

Reads one UTF-8 character.

Throws E.IllegalByte when encountering an invalid UTF-8 byte.

FUNC $readLine() string @public

     

Reads and returns one line, excluding the terminating NL.

Drops the CR characters that precede the NL but keeps CR characters halfway the line.

When at end of file returns NIL.

This is done in binary mode, there are no checks for valid UTF-8 characters.

FUNC $readLineRaw() string @public

     

Reads and returns one line, including the terminating NL.

When at end of file returns NIL.

This is done in binary mode, there are no checks for valid UTF-8 characters.

FUNC $write(string text) status @default @public

     

Writes text to the file. Returns FAIL or OK.

FUNC $writeAllLines(list<string> lines) status @public

     

Writes lines to the file.

Puts a line break after each line.

Returns FAIL when not all the lines could be written.

FUNC $writeByte(int byte) status @default @replace @public

     

Writes byte byte to the file.

Only the lower 8 bits of byte are used, the rest is ignored. Returns FAIL when the byte could not be written.

license

      Copyright 2009 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0