@@ -1154,12 +1154,11 @@ def print_figure_impl(fh):
11541154 xpdf_distill (tmpfile , isEPSF , ptype = papertype , bbox = bbox )
11551155
11561156 if passed_in_file_object :
1157- if file_requires_unicode (outfile ):
1158- with io .open (tmpfile , 'rb' ) as fh :
1159- outfile .write (fh .read ().decode ('latin-1' ))
1160- else :
1161- with io .open (tmpfile , 'rb' ) as fh :
1162- outfile .write (fh .read ())
1157+ fh = (io .open (tmpfile , 'r' , encoding = 'latin-1' )
1158+ if file_requires_unicode (outfile )
1159+ else io .open (tmpfile , 'rb' ))
1160+ with fh :
1161+ shutil .copyfileobj (fh , outfile )
11631162 else :
11641163 with io .open (outfile , 'w' ) as fh :
11651164 pass
@@ -1354,12 +1353,10 @@ def write(self, *kl, **kwargs):
13541353 rotated = psfrag_rotated )
13551354
13561355 if is_writable_file_like (outfile ):
1357- if file_requires_unicode (outfile ):
1358- with io .open (tmpfile , 'rb' ) as fh :
1359- outfile .write (fh .read ().decode ('latin-1' ))
1360- else :
1361- with io .open (tmpfile , 'rb' ) as fh :
1362- outfile .write (fh .read ())
1356+ with (io .open (tmpfile , 'r' , encoding = 'latin-1' )
1357+ if file_requires_unicode (outfile )
1358+ else io .open (tmpfile , 'rb' )) as fh :
1359+ shutil .copyfileobj (fh , outfile )
13631360 else :
13641361 with io .open (outfile , 'wb' ) as fh :
13651362 pass
0 commit comments