Skip to content

Commit f9d25b5

Browse files
[3.11] gh-67641: Clarify documentation on bytes vs text with non-seeking tarfile stream (GH-31610) (GH-113520)
(cherry picked from commit 0651936) Co-authored-by: Stanley <[email protected]>
1 parent 54927cd commit f9d25b5

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Doc/library/tarfile.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ Some facts and figures:
109109
``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile`
110110
object that processes its data as a stream of blocks. No random seeking will
111111
be done on the file. If given, *fileobj* may be any object that has a
112-
:meth:`~io.TextIOBase.read` or :meth:`~io.TextIOBase.write` method (depending on the *mode*). *bufsize*
113-
specifies the blocksize and defaults to ``20 * 512`` bytes. Use this variant
114-
in combination with e.g. ``sys.stdin``, a socket :term:`file object` or a tape
115-
device. However, such a :class:`TarFile` object is limited in that it does
112+
:meth:`~io.RawIOBase.read` or :meth:`~io.RawIOBase.write` method
113+
(depending on the *mode*) that works with bytes.
114+
*bufsize* specifies the blocksize and defaults to ``20 * 512`` bytes.
115+
Use this variant in combination with e.g. ``sys.stdin.buffer``, a socket
116+
:term:`file object` or a tape device.
117+
However, such a :class:`TarFile` object is limited in that it does
116118
not allow random access, see :ref:`tar-examples`. The currently
117119
possible modes:
118120

Lib/tarfile.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,11 @@ def write(self, s):
332332
class _Stream:
333333
"""Class that serves as an adapter between TarFile and
334334
a stream-like object. The stream-like object only
335-
needs to have a read() or write() method and is accessed
336-
blockwise. Use of gzip or bzip2 compression is possible.
337-
A stream-like object could be for example: sys.stdin,
338-
sys.stdout, a socket, a tape device etc.
335+
needs to have a read() or write() method that works with bytes,
336+
and the method is accessed blockwise.
337+
Use of gzip or bzip2 compression is possible.
338+
A stream-like object could be for example: sys.stdin.buffer,
339+
sys.stdout.buffer, a socket, a tape device etc.
339340
340341
_Stream is intended to be used only internally.
341342
"""

0 commit comments

Comments
 (0)