iostream¶
Stream wrapper for file descriptors and socket-like objects.
This module provides IOStream, a wrapper that normalizes read/write access across different types of file-like objects (files, sockets, etc.) by detecting available methods at construction time.
IOStream
¶
Wrapper that normalizes read/write operations on file-like objects.
Detects whether the underlying object has write/read methods (like files and sockets) or uses os.write/os.read (like raw file descriptors), and exposes a consistent .write() and .read() interface.
Example
import io
buf = io.BytesIO(b'payload')
data = iostream.IOStream(buf).read(4096) # b'payload'
Attributes:
| Name | Type | Description |
|---|---|---|
write |
A callable for writing data. |
|
read |
A callable for reading data. |
Source code in py_misc_utils/iostream.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |