fread_bytesT_fread_bytesFreadBytesFreadBytesfread_bytes (算子)

名称

fread_bytesT_fread_bytesFreadBytesFreadBytesfread_bytes — 从二进制文件读取字节。

签名

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]

描述

算子 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.

执行信息

参数

FileHandleFileHandleFileHandleFileHandlefileHandlefile_handle (输入控制)  file HFile, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

File handle.

NumberOfBytesNumberOfBytesNumberOfBytesNumberOfBytesnumberOfBytesnumber_of_bytes (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of bytes to be read.

ReadDataReadDataReadDataReadDatareadDataread_data (输出控制)  integer-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Bytes read from the input binary file.

IsEOFIsEOFIsEOFIsEOFisEOFis_eof (输出控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

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

示例(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)

结果

If an input file is open in binary mode and no file read error occurs,the operator fread_bytesfread_bytesFreadBytesFreadBytesFreadBytesfread_bytes 返回 2 ( H_MSG_TRUE )。否则,将抛出异常。

可能的前趋

open_fileopen_fileOpenFileOpenFileOpenFileopen_file

可能的后继

close_fileclose_fileCloseFileCloseFileCloseFileclose_file

替代

fread_charfread_charFreadCharFreadCharFreadCharfread_char

另见

open_fileopen_fileOpenFileOpenFileOpenFileopen_file, close_fileclose_fileCloseFileCloseFileCloseFileclose_file, fwrite_bytesfwrite_bytesFwriteBytesFwriteBytesFwriteBytesfwrite_bytes

模块

基础