Skip to content

iotoolz.utils

iotoolz.utils

Common io utils based on existing libs.

guess_encoding

Functions

peek_stream(stream, peek=None, ignore_closed=True)

Context manager to restore the stream position when exiting the context.

If the arg "peek" is provided, stream will start at the provided position when entering the context.

Parameters:

Name Type Description Default
stream ~T

Any stream object with the seek and tell method.

required
peek Optional[int]

stream position to start at when entering the context. Defaults to None.

None
ignore_closed bool

do not restore to position if file is already closed. Defaults to True.

True

Exceptions:

Type Description
TypeError

stream is not seekable.

Returns:

Type Description
Iterator[~T]

Iterator[T]: stream object with the modified position.


Last update: October 19, 2020