@@ -549,17 +549,30 @@ def _filemap_from_iobase(klass, io_obj: io.IOBase):
549
549
return klass .make_file_map ({klass .files_types [0 ][0 ]: io_obj })
550
550
551
551
@classmethod
552
- def _from_iobase (klass , io_obj : io .IOBase ):
552
+ def from_stream (klass , io_obj : io .IOBase ):
553
553
"""Load image from readable IO stream
554
554
555
555
Convert to BytesIO to enable seeking, if input stream is not seekable
556
+
557
+ Parameters
558
+ ----------
559
+ io_obj : IOBase object
560
+ Readable stream
556
561
"""
557
562
if not io_obj .seekable ():
558
563
io_obj = io .BytesIO (io_obj .read ())
559
564
return klass .from_file_map (klass ._filemap_from_iobase (io_obj ))
560
565
561
- def _to_iobase (self , io_obj : io .IOBase , ** kwargs ):
562
- """Save image from writable IO stream"""
566
+ def to_stream (self , io_obj : io .IOBase , ** kwargs ):
567
+ """Save image to writable IO stream
568
+
569
+ Parameters
570
+ ----------
571
+ io_obj : IOBase object
572
+ Writable stream
573
+ \*\*kwargs : keyword arguments
574
+ Keyword arguments that may be passed to ``img.to_file_map()``
575
+ """
563
576
self .to_file_map (self ._filemap_from_iobase (io_obj ), ** kwargs )
564
577
565
578
@classmethod
@@ -573,7 +586,7 @@ def from_bytes(klass, bytestring: bytes):
573
586
bstring : bytes
574
587
Byte string containing the on-disk representation of an image
575
588
"""
576
- return klass ._from_iobase (io .BytesIO (bytestring ))
589
+ return klass .from_stream (io .BytesIO (bytestring ))
577
590
578
591
def to_bytes (self , ** kwargs ) -> bytes :
579
592
r""" Return a ``bytes`` object with the contents of the file that would
@@ -590,7 +603,7 @@ def to_bytes(self, **kwargs) -> bytes:
590
603
Serialized image
591
604
"""
592
605
bio = io .BytesIO ()
593
- self ._to_iobase (bio , ** kwargs )
606
+ self .to_stream (bio , ** kwargs )
594
607
return bio .getvalue ()
595
608
596
609
@classmethod
@@ -603,6 +616,8 @@ def from_url(klass, url, timeout=5):
603
616
----------
604
617
url : str or urllib.request.Request object
605
618
URL of file to retrieve
619
+ timeout : float, optional
620
+ Time (in seconds) to wait for a response
606
621
"""
607
622
response = request .urlopen (url , timeout = timeout )
608
- return klass ._from_iobase (response )
623
+ return klass .from_stream (response )
0 commit comments