Teks sumber — English
Terjemahan — Bahasa Indonesia
Independent of its category, each concrete stream object will also have various capabilities: it can be read-only, write-only, or read-write. It can also allow arbitrary random access (seeking forwards or backwards to any location), or only sequential access (for example in the case of a socket or pipe).
All streams are careful about the type of data you give to them. For example giving a :class:`str` object to the :meth:`!write` method of a binary stream will raise a :exc:`TypeError`. So will giving a :class:`bytes` object to the :meth:`!write` method of a text stream.
Other library modules may provide additional ways to create text or binary streams. See :meth:`socket.socket.makefile` for example.
This function emits an :class:`EncodingWarning` if :data:`sys.flags.warn_default_encoding <sys.flags>` is true and *encoding* is ``None``. *stacklevel* specifies where the warning is emitted. For example::
The abstract base classes also provide default implementations of some methods in order to help implementation of concrete stream classes. For example, :class:`BufferedIOBase` provides unoptimized implementations of :meth:`!readinto` and :meth:`!readline`.
Read bytes into a pre-allocated, writable :term:`bytes-like object` *b*, and return the number of bytes read. For example, *b* might be a :class:`bytearray`.
See the :func:`open` built-in function for examples on using the *opener* parameter.
Read bytes into a pre-allocated, writable :term:`bytes-like object` *b* and return the number of bytes read. For example, *b* might be a :class:`bytearray`.
For example::
Sebagai contoh::
By reading and writing only large chunks of data even when the user asks for a single byte, buffered I/O hides any inefficiency in calling and executing the operating system's unbuffered I/O routines. The gain depends on the OS and the kind of I/O which is performed. For example, on some modern OSes such as Linux, unbuffered disk I/O can be as fast as buffered I/O. The bottom line, however, is that buffered I/O offers predictable performance regardless of the platform and the backing device. Therefore, it is almost always preferable to use buffered I/O rather than unbuffered I/O for binary data.