Skip to content

fread_bytesFreadBytesFreadBytesfread_bytesT_fread_bytes🔗

Short description🔗

fread_bytesFreadBytesFreadBytesfread_bytesT_fread_bytes — Read bytes from a binary file.

Signature🔗

fread_bytes( file FileHandle, integer NumberOfBytes, out integer ReadData, out integer IsEOF )void FreadBytes( const HTuple& FileHandle, const HTuple& NumberOfBytes, HTuple* ReadData, HTuple* IsEOF )static void HOperatorSet.FreadBytes( HTuple fileHandle, HTuple numberOfBytes, out HTuple readData, out HTuple isEOF )def fread_bytes( file_handle: HHandle, number_of_bytes: int ) -> Tuple[Sequence[int], int]

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

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

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

Description🔗

The operator fread_bytesFreadBytes reads bytes from the input file defined by FileHandlefileHandlefile_handle. The input file must have been opened with open_fileOpenFile in binary format.

The number of bytes to be read, greater than 00, is specified as NumberOfBytesnumberOfBytesnumber_of_bytes.

The bytes that are read are returned in ReadDatareadDataread_data. IsEOFisEOFis_eof is set to 11 if end of file is reached while reading the bytes from the input binary file. Otherwise, it is set to 00.

When the number of bytes to be read is larger than the number of bytes in the input binary file, the operator fread_bytesFreadBytes returns all bytes read till the end of the file in ReadDatareadDataread_data and parameter IsEOFisEOFis_eof is set to 11.

If no byte can be read because the end of the file is reached, ReadDatareadDataread_data is empty and IsEOFisEOFis_eof is set to 11.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

FileHandlefileHandlefile_handle (input_control) file → (handle)HTuple (HHandle)HFile, HTuple (IntPtr)HHandleHtuple (handle)

File handle.

NumberOfBytesnumberOfBytesnumber_of_bytes (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Number of bytes to be read.

ReadDatareadDataread_data (output_control) integer-array → (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Bytes read from the input binary file.

IsEOFisEOFis_eof (output_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (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_bytesFreadBytes returns 2 (H_MSG_TRUE). Otherwise, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

open_fileOpenFile

Possible successors

close_fileCloseFile

Alternatives

fread_charFreadChar

See also

open_fileOpenFile, close_fileCloseFile, fwrite_bytesFwriteBytes

Module🔗

Foundation