fread_bytesT_fread_bytesFreadBytesFreadBytes (Operator)

Name

fread_bytesT_fread_bytesFreadBytesFreadBytes — Read bytes from a binary file.

Signature

fread_bytes( : : FileHandle, NumberOfBytes : ReadData, IsEOF)

Herror T_fread_bytes(const Htuple FileHandle, const Htuple NumberOfBytes, Htuple* ReadData, Htuple* IsEOF)

void FreadBytes(const HTuple& FileHandle, const HTuple& NumberOfBytes, HTuple* ReadData, HTuple* IsEOF)

HTuple HFile::FreadBytes(Hlong NumberOfBytes, Hlong* IsEOF) const

static void HOperatorSet.FreadBytes(HTuple fileHandle, HTuple numberOfBytes, out HTuple readData, out HTuple isEOF)

HTuple HFile.FreadBytes(int numberOfBytes, out int isEOF)

Description

The operator fread_bytesfread_bytesFreadBytesFreadBytesFreadBytes reads bytes from the input file defined by FileHandleFileHandleFileHandleFileHandlefileHandle. The input file must have been opened with open_fileopen_fileOpenFileOpenFileOpenFile in binary format.

The number of bytes to be read, greater than 0, is specified as NumberOfBytesNumberOfBytesNumberOfBytesNumberOfBytesnumberOfBytes.

The bytes that are read are returned in ReadDataReadDataReadDataReadDatareadData. IsEOFIsEOFIsEOFIsEOFisEOF is set to 1 if end of file is reached while reading the bytes from the input binary file. Otherwise, it is set to 0.

When the number of bytes to be read is larger than the number of bytes in the input binary file, the operator fread_bytesfread_bytesFreadBytesFreadBytesFreadBytes returns all bytes read till the end of the file in ReadDataReadDataReadDataReadDatareadData and parameter IsEOFIsEOFIsEOFIsEOFisEOF is set to 1.

If no byte can be read because the end of the file is reached, ReadDataReadDataReadDataReadDatareadData is empty and IsEOFIsEOFIsEOFIsEOFisEOF is set to 1.

Execution Information

Parameters

FileHandleFileHandleFileHandleFileHandlefileHandle (input_control)  file HFile, HTupleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

File handle.

NumberOfBytesNumberOfBytesNumberOfBytesNumberOfBytesnumberOfBytes (input_control)  integer HTupleHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of bytes to be read.

ReadDataReadDataReadDataReadDatareadData (output_control)  integer-array HTupleHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Bytes read from the input binary file.

IsEOFIsEOFIsEOFIsEOFisEOF (output_control)  integer HTupleHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Indicates if end of file is reached while reading the file.

Example (HDevelop)

* Read a binary file 5 bytes at a time till EOF is reached.
open_file(Filename,'input_binary',FileHandle)
repeat
	fread_bytes(FileHandle, 5, BytesRead, IsEOF)
until (IsEOF)
close_file (FileHandle)

Result

If an input file is open in binary mode and no file read error occurs,the operator fread_bytesfread_bytesFreadBytesFreadBytesFreadBytes returns 2 (H_MSG_TRUE). Otherwise, an exception is raised.

Possible Predecessors

open_fileopen_fileOpenFileOpenFileOpenFile

Possible Successors

close_fileclose_fileCloseFileCloseFileCloseFile

Alternatives

fread_charfread_charFreadCharFreadCharFreadChar

See also

open_fileopen_fileOpenFileOpenFileOpenFile, close_fileclose_fileCloseFileCloseFileCloseFile, fwrite_bytesfwrite_bytesFwriteBytesFwriteBytesFwriteBytes

Module

Foundation