fread_bytesT_fread_bytesFreadBytesFreadBytesfread_bytes (Operator)

Name

fread_bytesT_fread_bytesFreadBytesFreadBytesfread_bytes — 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)

def fread_bytes(file_handle: HHandle, number_of_bytes: int) -> Tuple[Sequence[int], int]

Description

The operator fread_bytesfread_bytesFreadBytesFreadBytesFreadBytesfread_bytes reads bytes from the input file defined by FileHandleFileHandleFileHandleFileHandlefileHandlefile_handle. The input file must have been opened with open_fileopen_fileOpenFileOpenFileOpenFileopen_file in binary format.

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

The bytes that are read are returned in ReadDataReadDataReadDataReadDatareadDataread_data. IsEOFIsEOFIsEOFIsEOFisEOFis_eof 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_bytesFreadBytesFreadBytesFreadBytesfread_bytes returns all bytes read till the end of the file in ReadDataReadDataReadDataReadDatareadDataread_data and parameter IsEOFIsEOFIsEOFIsEOFisEOFis_eof is set to 1.

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

Execution Information

Parameters

FileHandleFileHandleFileHandleFileHandlefileHandlefile_handle (input_control)  file HFile, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

File handle.

NumberOfBytesNumberOfBytesNumberOfBytesNumberOfBytesnumberOfBytesnumber_of_bytes (input_control)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of bytes to be read.

ReadDataReadDataReadDataReadDatareadDataread_data (output_control)  integer-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Bytes read from the input binary file.

IsEOFIsEOFIsEOFIsEOFisEOFis_eof (output_control)  integer HTupleintHTupleHtuple (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_bytesFreadBytesFreadBytesFreadBytesfread_bytes returns TRUE. Otherwise, an exception is raised.

Possible Predecessors

open_fileopen_fileOpenFileOpenFileOpenFileopen_file

Possible Successors

close_fileclose_fileCloseFileCloseFileCloseFileclose_file

Alternatives

fread_charfread_charFreadCharFreadCharFreadCharfread_char

See also

open_fileopen_fileOpenFileOpenFileOpenFileopen_file, close_fileclose_fileCloseFileCloseFileCloseFileclose_file, fwrite_bytesfwrite_bytesFwriteBytesFwriteBytesFwriteBytesfwrite_bytes

Module

Foundation