ARSA Language  2.8
(Encryption, GPU and Web 3.0)
file.h File Reference

Go to the source code of this file.

Functions

int fopen (const char *filename, const char *mode, bool cache=false, const char *filename_ex="")
 create a new file or to open an existing file. More...
 
void fclose (int id, const char *mode="r")
 close a file More...
 
bool feof (int id)
 is current position on file at the end More...
 
const char * fgets (int id)
 read string on a file until found '\n' or eof More...
 
void fprintf (int id, const char *str)
 write a string into a file More...
 
long fsize (int id, const char *mode="r")
 get file size More...
 
long fpos (int id, const char *mode="r")
 get current position on a file More...
 
void fseek (int id, int finalPos, const char *mode="r")
 Changes position in file. More...
 
bool fexist (const char *filename)
 is this file exist on drive More...
 
bool fadd (const char *filename, const char *mode, bool cache=true, const char *filename_ex="", const char *archive_type="zip", const char *password="")
 
bool faddzip (const char *zipfilename, const const char *password="")
 
bool fremove (const char *filename)
 
const char * ftostring (const char *filename, const char *encode="utf8")
 Open file and allocate buffer to string, no drop file pointer. More...
 
bool fdel (const char *filename)
 delete file from disk. More...
 
const char * fread (int id, int len)
 read string start from current position until len count. More...
 
const char * freadf (const char *filename, int seekpos, int len)
 read file start from seekpos until len count. More...
 
const char * fgetsf (const char *filename, int line_nb)
 read string on a file until found '\n' and at line number count. More...
 
int fsizef (const char *filename)
 get file size More...
 
const char * ftointernalstorage (const char *filename)
 

Detailed Description

Example Read File

{
set($fp, fopen("credit-utf-8.txt","r") )
while(1) procedure( if(feof($fp)==true) break() >> addstring($msg_utf_8,fgets($fp)) )
fclose($fp,"r")
}function(init)
text(720, 0, "credit-utf-8.txt UTF-8",100,0,0,255)
text(280,30,"$msg_utf_8")

Example Write File

{
set($fp, fopen("test.txt","w") )
fprintf( $fp, "Hello World\n" )
fprintf( $fp, "This is write text to file.\n" )
fclose($fp, "w")
}function(init)
ifelse($ret!=-1,text(10,10, "Please see output -> test.txt"),text(10,10, "Error! -> test.txt"))

Definition in file file.h.

Function Documentation

◆ fadd()

bool fadd ( const char *  filename,
const char *  mode,
bool  cache = true,
const char *  filename_ex = "",
const char *  archive_type = "zip",
const char *  password = "" 
)

Adds an archive to the file system.
After calling this, the Engine will also search and open files directly from this archive. This is useful for hiding data from the end user, speeding up file access and making it possible to access for example Quake3 .pk3 files, which are just renamed .zip files.
By default: supports ZIP, PAK, TAR, PNK, and directories as archives.
Supports AES-encrypted zip files, and the advanced compression techniques lzma and bzip2.

Parameters
filenameFilename of the archive to add to the file system.
modemust be "r"
cacheallocate to system memory before reading.
filename_exis a new name of file, in case download from cloud e.g. google drive, dropbox
archive_typesupport archive type follows: (default is "zip")
"zip"
"gzip"
"pak"
"tar"
passwordarchive password
Returns
true was successed, false was failed

◆ faddzip()

bool faddzip ( const char *  zipfilename,
const const char *  password = "" 
)

Adds ZIP archive to the file system.
After calling this, the Engine will also search and open files directly from this archive. This is useful for hiding data from the end user, speeding up file access.
By default: supports ZIP only!!!.
Supports AES-encrypted zip files, and the advanced compression techniques lzma and bzip2.

Parameters
zipfilenameZIP Filename of the archive to add to the file system.
passwordarchive password
Returns
true was successed, false was failed

◆ fclose()

void fclose ( int  id,
const char *  mode = "r" 
)

close a file

Parameters
idfile id
modedefault is "r", should be same mode to fopen() call

◆ fdel()

bool fdel ( const char *  filename)

delete file from disk.

Parameters
filenameFilename of the file on disk.
Returns
true was successed, false was failed

◆ feof()

bool feof ( int  id)

is current position on file at the end

Parameters
idfile id
Returns
true is end, false is not

◆ fexist()

bool fexist ( const char *  filename)

is this file exist on drive

Parameters
filenameis a string literal, which you will use to name your file
Returns
true is end, false is not

◆ fgets()

const char* fgets ( int  id)

read string on a file until found '\n' or eof

Parameters
idfile id
Returns
string

◆ fgetsf()

const char* fgetsf ( const char *  filename,
int  line_nb 
)

read string on a file until found '\n' and at line number count.

Parameters
filenameis a string literal, which you will use to operation.
line_nbline number count, zero based.
Returns
string, empty is otherwise.

◆ fopen()

int fopen ( const char *  filename,
const char *  mode,
bool  cache = false,
const char *  filename_ex = "" 
)

create a new file or to open an existing file.

Parameters
filenameis a string literal, which you will use to name your file
modecan have one of the following values:
r : Opens an existing text file for reading purpose.
w : Opens a text file for writing. If it does not exist, then a new file is created. Here your program will start writing content from the beginning of the file.
wa : Opens a text file for writing in appending mode. If it does not exist, then a new file is created. Here your program will start appending content in the existing file content.
cacheallocate to system memory before reading.
filename_exis a new name of file, in case download from cloud e.g. google drive, dropbox
Returns
id of file, > -1 was successed, -1 was failed

◆ fpos()

long fpos ( int  id,
const char *  mode = "r" 
)

get current position on a file

Parameters
idfile id
modedefault is "r", should be same mode to fopen() call
Returns
current position

◆ fprintf()

void fprintf ( int  id,
const char *  str 
)

write a string into a file

Parameters
idfile id
strstring that put on a file

◆ fread()

const char* fread ( int  id,
int  len 
)

read string start from current position until len count.

Parameters
idfile id
lensize of read.
Returns
string

◆ freadf()

const char* freadf ( const char *  filename,
int  seekpos,
int  len 
)

read file start from seekpos until len count.

Parameters
filenameis a string literal, which you will use to operation.
seekposstart position to read.
lensize of read.
Returns
string, empty is otherwise.

◆ fremove()

bool fremove ( const char *  filename)

Removes an archive from the file system.
This will close the archive and free any file handles, but will not close resources which have already been loaded and are now cached, for example textures and meshes.

Parameters
filenameFilename of the archive to add to the file system.
Returns
true was successed, false was failed

◆ fseek()

void fseek ( int  id,
int  finalPos,
const char *  mode = "r" 
)

Changes position in file.

Parameters
idfile id
finalPosDestination position in the file.
modedefault is "r", should be same mode to fopen() call

◆ fsize()

long fsize ( int  id,
const char *  mode = "r" 
)

get file size

Parameters
idfile id
modedefault is "r", should be same mode to fopen() call
Returns
file size

◆ fsizef()

int fsizef ( const char *  filename)

get file size

Parameters
filenameis a string literal, which you will use to operation.
Returns
file size

◆ ftointernalstorage()

const char* ftointernalstorage ( const char *  filename)

copy file to internal storage, purpose for read or shrare file.
may this only support for mobile devices.
win32, psp, psvita, ps2 is not thing to do.

Parameters
filenameis a string literal, which you will use to operation.
Returns
new file path on internal storage, empty is otherwise.

◆ ftostring()

const char* ftostring ( const char *  filename,
const char *  encode = "utf8" 
)

Open file and allocate buffer to string, no drop file pointer.

Parameters
filenameis a string literal, which you will use to name your file
encodeforce encoding string to. default: utf8, (ascii for binary file)
auto
ascii
utf8
utf16
utf32
wchar
Returns
string buffer, no need drop buffer