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_bytesFreadBytesFreadBytesfread_bytes reads bytes from the input file defined by FileHandleFileHandleFileHandlefileHandlefile_handle. The input file must have been opened with open_fileopen_fileOpenFileOpenFileopen_file in binary format.

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

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

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

Execution Information

Parameters

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

File handle.

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

Number of bytes to be read.

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

Bytes read from the input binary file.

IsEOFIsEOFIsEOFisEOFis_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_bytesFreadBytesFreadBytesfread_bytes returns 2 ( H_MSG_TRUE) . Otherwise, an exception is raised.

Possible Predecessors

open_fileopen_fileOpenFileOpenFileopen_file

Possible Successors

close_fileclose_fileCloseFileCloseFileclose_file

Alternatives

fread_charfread_charFreadCharFreadCharfread_char

See also

open_fileopen_fileOpenFileOpenFileopen_file, close_fileclose_fileCloseFileCloseFileclose_file, fwrite_bytesfwrite_bytesFwriteBytesFwriteBytesfwrite_bytes

Module

Foundation