Support temporary file

Official web site : http://www.scolring.org/.

Plateform : Windows XP or +, GNU / Linux with glib > 2.x

Scol : 4.0 or +

Features

Open, close, read and write to the temporary file

Compilation

No specific way.

Scol api

List of functions

FileTemp

FileTemp is a new type

It describes a new temporary file.

_FILEOpenTemp

_FILEOpenTemp is a function to open a new temporary file.
This function opens a unique temporary file in binary read/write mode. The file will be automatically deleted when it is closed or the program terminates.

Prototype

Prototype : _FILEOpenTemp
ReturnTypeNameDescription
fun [Chn] FileTemp
-Chnchannela channel in which the connection will be created
FileTemp--New scol object, or nil if error (open the log to see the error returned)

Example

Open a new temporary file, save to any datas and read it.

typeof ftmp = FileTemp;;
typeof s = S;;

fun main()=
	_showconsole;

	set ftmp = _FILEOpenTemp _channel;

	_FILEWriteTmp ftmp "Scol  a good language !";
	_FILESeekTemp ftmp 5 0;
	_FILEWriteTmp ftmp "is";
	_FILESeekTemp ftmp 0 0;
	set s = _FILEReadTemp ftmp 25;
	_fooS strcat "Temp : " s;

	_FILECloseTemp ftmp;
	0;;


_FILECloseTemp

Destroy a temporary file Scol object. The physical file will be automatically deleted.

Prototype

Prototype : _FILECloseTemp
ReturnTypeNameDescription
fun [FileTemp] I
-FileTempfileany temporary file Scol object already created.
I--0, or nil if error

_FILEReadTemp

Read to a number of bytes of a temporary file from the curent position of its cursor.

Prototype

Prototype : _FILEReadTemp
ReturnTypeNameDescription
fun [FileTemp I] S
-FileTempfileany temporary file Scol object already created.
-Ibytesthe number of bytes to read.
S--the string read or nil if error

_FILESizeTemp

Return the size of a temporary file.

Prototype

Prototype : _FILESizeTemp
ReturnTypeNameDescription
fun [FileTemp] S
-FileTempfileany temporary file Scol object already created.
I--its size or nil if error

_FILETellTemp

Return the current cursor's position of a temporary file.

Prototype

Prototype : _FILETellTemp
ReturnTypeNameDescription
fun [FileTemp] S
-FileTempfileany temporary file Scol object already created.
I--its position or nil if error

_FILESeekTemp

Move the cursor to a temporary file.

Prototype

Prototype : _FILESeekTemp
ReturnTypeNameDescription
fun [FileTemp I I] S
-FileTempfileany temporary file Scol object already created.
-Ibytesthe number of bytes to move.
-IfromThis flag can take 3 values :
  • 0 : le cursor will be moved to _bytes_ bytes from the begin of the file (default)
  • 1 : le cursor will be moved to _bytes_ bytes from its current position
  • 2 : le cursor will be moved to _bytes_ bytes from the end of the file
I--0 or nil if error

_FILEWriteTmp

Write a string to a temporary file from the current position of its cursor.
If needed, move the cursor (_FILESeekTemp) before to write it.

Prototype

Prototype : _FILEWriteTmp
ReturnTypeNameDescription
fun [FileTemp S] I
-FileTempfileany temporary file Scol object already created.
-Sbytesthe string to write.
I--0 or nil if error