Siebel eScript Language Reference > Siebel eScript Commands > File I/O Methods in eScript >
Clib.fread() Method
This method reads data from an open file and stores it in a variable. Syntax A
Clib.fread(destBuffer, bytelength, filePointer)
Syntax B
Clib.fread(destVar, varDescription, filePointer)
Syntax C
Clib.fread(blobVar, blobDescriptor, filePointer)
|
|
destBuffer |
A variable indicating the buffer to contain the data read from the file |
bytelength |
The number of bytes to read |
filePointer |
A file pointer as returned by Clib.fopen() |
destVar |
A variable to contain the data read from the file |
varDescription |
A variable that describes how much data is to be read; must be one of the values in the list in the "Usage" section |
blobVar |
A variable indicating the BLOB to contain the data read from the file |
blobDescriptor |
The blobDescriptor for blobVar |
Returns
The number of elements read. For destBuffer, the number of bytes read, up to bytelength. For varDescription, 1 if the data is read, or 0 if there is a read error or EOF is encountered. Usage
This method reads data from the open file filePointer and stores it in the specified variable. If it does not yet exist, the variable, buffer, or BLOB is created. The varDescription value is a variable that describes how and how much data is to be read: if destVar is to hold a single datum, then varDescription must be one shown in the following table.
|
|
UWORD8 |
Stored as an unsigned byte |
SWORD8 |
Stored as a signed byte |
UWORD16 |
Stored as an unsigned 16-bit integer |
SWORD16 |
Stored as a signed 16-bit integer |
UWORD24 |
Stored as an unsigned 24-bit integer |
SWORD24 |
Stored as a signed 24-bit integer |
UWORD32 |
Stored as an unsigned 32-bit integer |
SWORD32 |
Stored as a signed 32-bit integer |
FLOAT32 |
Stored as a floating-point number |
FLOAT64 |
Stored as a double-precision floating-point number |
For example, the definition of a structure might be: ClientDef = new blobDescriptor(); ClientDef.Sex = UWORD8; ClientDef.MaritalStatus = UWORD8; ClientDef._Unused1 = UWORD16; ClientDef.FirstName = 30; ClientDef.LastName = 40; ClientDef.Initial = UWORD8;
The Siebel eScript version of fread() differs from the standard C version in that the standard C library is set up for reading arrays of numeric values or structures into consecutive bytes in memory. In JavaScript, this is not necessarily the case. Data types are read from the file in a byte-order described by the current value of the BigEndianMode global variable. Example
To read the 16-bit integer i , the 32-bit float f , and then the 10-byte buffer buf from the open file fp , use code like this: if ( !Clib.fread(i, SWORD16, fp) || !Clib.fread(f, FLOAT32, fp) || 10 != Clib.fread(buf, 10, fp) ) TheApplication().RaiseErrorText("Error reading from file.\n"); }
See Also
Clib.fwrite() Method
|