Skip to content

Async file

An async file-like object for reading and writing data.

Created by the open method of the AsyncOperator class.

closed property #

Whether this file is closed.

Returns:

Type Description
coroutine

An awaitable that returns True if this file is closed.

close() #

Close this file.

This also flushes write buffers, if applicable.

Notes

A closed file cannot be used for further I/O operations.

read(size=None) #

Read at most size bytes from this file asynchronously.

If size is not specified, read until EOF.

Parameters:

Name Type Description Default
size int

The maximum number of bytes to read.

None
Notes

Fewer bytes may be returned than requested, read in a loop to ensure all bytes are read.

Returns:

Type Description
coroutine

An awaitable that returns the bytes read from the stream.

readable() #

Whether this file can be read from.

Returns:

Type Description
coroutine

An awaitable that returns True if this file can be read from.

seek(pos, whence=0) #

Change the position of this file to the given byte offset.

Parameters:

Name Type Description Default
pos int

The byte offset (position) to set.

required
whence int

The reference point for the offset. 0: start of file (default); 1: current position; 2: end of file.

0
Notes

Unbounded readable files allow non-negative positions beyond EOF. Reads from those positions return empty bytes when the backing service reports an unsatisfied unbounded range. Other service errors propagate. Explicit bounded views reject positions beyond their range.

Returns:

Type Description
coroutine

An awaitable that returns the current absolute position.

seekable() #

Whether this file can be repositioned.

Notes

This is only applicable to readable files.

Returns:

Type Description
coroutine

An awaitable that returns True if this file can be repositioned.

tell() #

Return the current position of this file.

Returns:

Type Description
coroutine

An awaitable that returns the current absolute position.

writable() #

Whether this file can be written to.

Returns:

Type Description
coroutine

An awaitable that returns True if this file can be written to.

write(bs) #

Write bytes to this file asynchronously.

Parameters:

Name Type Description Default
bs bytes

The bytes to write to the file.

required

Returns:

Type Description
coroutine

An awaitable that returns the number of bytes written.