Use cFilesystem.pkg Class cFileSystemUchar is a cFilesystem Procedure Construct_Object Forward Send Construct_Object End_Procedure Procedure End_Construct_Object Forward Send End_Construct_Object End_Procedure // Reading from a binary file. // The data read from the file is placed in sReadBuffer (UChar[]) and the function returns the number of bytes read. // Then the function returns 0 end of file has been reached (pbEOF will then be true) or an error has occured (pbError will then be true). // No errors occures if you try to read past end of file. // To speed up reading process you should read in a block of data at a time (i.e. iNumberOfBytes = 2000) instead of // reading one byte at a time. No errors occures if you try to read past end of file. Function BinaryFileReadUChar Integer iFilenumber Integer iNumberOfBytes UChar[] ByRef sReadBuffer Returns Integer Handle hFileHandle Integer iBytesRead iErrorNumber Boolean bOk Set pbError to False Move 0 to iBytesRead If (iNumberOfBytes < 1) Begin Send warning_box "Number of bytes to read can not be less than one." Function_Return iBytesRead End Get BinaryFileHandle iFilenumber to hFileHandle If hFileHandle Begin Move (ResizeArray(sReadBuffer, iNumberOfBytes)) to sReadBuffer Move (fsReadFile(hFileHandle, AddressOf(sReadBuffer), iNumberOfBytes, (AddressOf(iBytesRead)), FNULL)) to bOk If (bOk = False) Begin Move (fsGetLastError()) to iErrorNumber If iErrorNumber Send DoShowError iErrorNumber (FileErrorText(Self, iFilenumber)) End Else Begin If (iBytesRead = 0 or iBytesRead <> iNumberOfBytes) Begin Set pbEOF to True Move (ResizeArray(sReadBuffer, iBytesRead)) to sReadBuffer End End End Else Send warning_box FS_FILEHANDLEMISSING Function_Return iBytesRead End_Function // Writing to a binary file. // Returns true if the data was written to the file without error. Function BinaryFileWriteUChar Integer iFilenumber UChar[] ByRef sWriteData Returns Boolean Integer iBytesWritten iBytesToWrite iErrorNumber Handle hFileHandle Boolean bOk Set pbError to False Move False to bOk Get BinaryFileHandle iFilenumber to hFileHandle If hFileHandle Begin Move 0 to iBytesWritten Move (SizeOfArray(sWriteData)) to iBytesToWrite Move (fsWriteFile(hFileHandle, AddressOf(sWriteData), iBytesToWrite, AddressOf(iBytesWritten), FNULL)) to bOk If (bOk = False) Begin Move (fsGetLastError()) to iErrorNumber If iErrorNumber Send DoShowError iErrorNumber (FileErrorText(Self, iFilenumber)) End If (iBytesToWrite <> iBytesWritten) Begin Send Warning_box "Not all data could be written!" Move False to bOk End End Else Send warning_box FS_FILEHANDLEMISSING Function_Return bOk End_Function End_Class