Skip to content

Commit 95e3194

Browse files
committed
Improved documentation for _pulls_fd and _pushes_fd
1 parent 3b79a77 commit 95e3194

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/handbook/writing-your-own-image-plugin.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ from the file like object.
395395

396396
Alternatively, if ``pulls_fd`` is set, then the decode function is
397397
called once, with an empty buffer. It is the decoder's responsibility
398-
to decode the entire tile in that one call.
398+
to decode the entire tile in that one call. Using this will provide a
399+
codec with more freedom, but that freedom may mean increased memory usage
400+
if entire tile is held in memory at once by the codec.
399401

400402
If an error occurs, set ``state->errcode`` and return -1.
401403

@@ -429,6 +431,13 @@ Python-based file codec:
429431
a buffer of data to be interpreted, or the ``encode`` method is repeatedly
430432
called with the size of data to be output.
431433

434+
Alternatively, if the decoder's ``_pulls_fd`` property (or the encoder's
435+
``_pushes_fd`` property) is set to ``True``, then ``decode`` and ``encode``
436+
will only be called once. In the decoder, ``self.fd`` can be used to access
437+
the file-like object. Using this will provide a codec with more freedom, but
438+
that freedom may mean increased memory usage if entire file is held in
439+
memory at once by the codec.
440+
432441
In ``decode``, once the data has been interpreted, ``set_as_raw`` can be
433442
used to populate the image.
434443

src/PIL/ImageFile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ def encode(self, bufsize):
725725

726726
def encode_to_pyfd(self):
727727
"""
728+
If ``pushes_fd`` is ``True``, then this method will be used,
729+
and ``encode()`` will only be called once.
730+
728731
:returns: A tuple of ``(bytes consumed, errcode)``.
729732
Err codes are from :data:`.ImageFile.ERRORS`.
730733
"""

0 commit comments

Comments
 (0)