(int, string) = ReadFile(hFile, buffer/bufSize , overlapped )

Reads a string from a file


hFile : PyHANDLE/int

Handle to the file

buffer/bufSize : PyOVERLAPPEDReadBuffer/int

Size of the buffer to create for the result, or a buffer to fill with the result. If a buffer object and overlapped is passed, the result is the buffer itself. If a buffer but no overlapped is passed, the result is a new string object, built from the buffer, but with a length that reflects the data actually read.

overlapped=None : PyOVERLAPPED

An overlapped structure


in a multi-threaded overlapped environment, it is likely to be necessary to pre-allocate the read buffer using the win32file::AllocateReadBuffer method, otherwise the I/O operation may complete before you can assign to the resulting buffer.

Return Value

The result is a tuple of (hr, string/PyOVERLAPPEDReadBuffer), where hr may be 0, ERROR_MORE_DATA or ERROR_IO_PENDING. If the overlapped param is not None, then the result is a PyOVERLAPPEDReadBuffer. Once the overlapped IO operation has completed, you can convert this to a string (str(object)) [py2k] or (bytes(object)) [py3k] to obtain the data. While the operation is in progress, you can use the slice operations (object[:end]) to obtain the data read so far. You must use the OVERLAPPED API functions to determine how much of the data is valid.