Always call close() when finished with the file.
Public Member Functions | |
ParaFileObject (CParaFile *pFile) | |
bool | IsValid () |
whether file is valid | |
void | close () |
Close the current file. | |
int | SetSegment (int nFromByte, int nByteCount) |
by setting the segment, we can inform NPL that we only transmit the file content in the segment to a remote place. | |
const char * | GetBase64StringEx (int *pnStrLength=0) |
get base 64 string of the binary data in the current file segment. | |
const char * | GetBase64String () |
void | seek (int offset) |
always call seek(0) if one opens a old file for overwritten | |
void | seekRelative (int offset) |
void | SetFilePointer (int lDistanceToMove, int dwMoveMethod) |
The SetFilePointer function moves the file pointer of an open file. | |
bool | SetEndOfFile () |
The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.This function can be used to truncate or extend a file. | |
void | WriteString (const char *str) |
write a string to the current file. | |
void | writeline (const char *str) |
const char * | readline () |
read line as a string. | |
const char * | GetText () |
get the content of the file as text | |
const char * | GetText2 (int fromPos, int nCount) |
get the content of the file as text between two Log positions. | |
void | write (const char *buffer, int nSize) |
write a buffer to the current file. | |
int | WriteBytes (int nSize, const object &input) |
write bytes to file; e.g. | |
object | ReadBytes (int nSize, const object &output) |
read bytes from file. | |
int | GetFileSize () |
get the file size in bytes. | |
Public Attributes | |
CParaFile * | m_pFile |
int | m_nFromByte |
int | m_nByteCount |
void ParaScripting::ParaFileObject::close | ( | ) |
Close the current file.
int ParaScripting::ParaFileObject::SetSegment | ( | int | nFromByte, | |
int | nByteCount | |||
) |
by setting the segment, we can inform NPL that we only transmit the file content in the segment to a remote place.
it also affects the returned result of the GetBase64String.
nFromByte,: | from which byte | |
nByteCount,: | number of bytes of the segment. if -1, it is end of file. |
const char * ParaScripting::ParaFileObject::GetBase64StringEx | ( | int * | pnStrLength = 0 |
) |
get base 64 string of the binary data in the current file segment.
to change segment, use SetSegment.
pnStrLength,: | [out] length of the returned string. |
void ParaScripting::ParaFileObject::SetFilePointer | ( | int | lDistanceToMove, | |
int | dwMoveMethod | |||
) |
The SetFilePointer function moves the file pointer of an open file.
this function only works when the ParaFile object is an actual windows file, instead of a virtual file. for virtual file, use the seek and seekRelative function.
lDistanceToMove | ||
dwMoveMethod | 0: FILE_BEGIN The starting point is 0 (zero) or the beginning of the file. 1: FILE_CURRENT The starting point is the current value of the file pointer. 2: FILE_END The starting point is the current end-of-file position. |
bool ParaScripting::ParaFileObject::SetEndOfFile | ( | ) |
The SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.This function can be used to truncate or extend a file.
If the file is extended, the contents of the file between the old EOF position and the new position are not defined.
void ParaScripting::ParaFileObject::WriteString | ( | const char * | str | ) |
write a string to the current file.
const char * ParaScripting::ParaFileObject::readline | ( | ) |
read line as a string.
The string is guaranteed to be ended with ''. if end of file is reached, it will return NULL. which is nil in the script. if a line begins with "--", it is automatically recognized as a comment line and will be skipped. a blank line will also be skipped.
const char * ParaScripting::ParaFileObject::GetText2 | ( | int | fromPos, | |
int | nCount | |||
) |
get the content of the file as text between two Log positions.
fromPos,: | position in bytes. | |
nCount,: | nCount in bytes. if -1, it defaults to end of log file. |
void ParaScripting::ParaFileObject::write | ( | const char * | buffer, | |
int | nSize | |||
) |
write a buffer to the current file.
int ParaScripting::ParaFileObject::WriteBytes | ( | int | nSize, | |
const object & | input | |||
) |
write bytes to file; e.g.
local nBytes = file:WriteBytes(3, {[1]=255, [2]=0, [3]=128});
nSize,: | number of bytes to write | |
input,: | array of integers, each represents a byte |
object ParaScripting::ParaFileObject::ReadBytes | ( | int | nSize, | |
const object & | output | |||
) |
read bytes from file.
e.g. local data={};local nBytes = file:ReadBytes(3, data); data[1], data[2], data[3]
nSize,: | number of bytes to read | |
output,: | in/out, it should be an empty table. When the function returns, it will contain an array of integers, each represents a byte |
int ParaScripting::ParaFileObject::GetFileSize | ( | ) |
get the file size in bytes.