MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / copyfileobj

Function copyfileobj

tools/python-3.11.9-amd64/Lib/tarfile.py:239–262  ·  view source on GitHub ↗

Copy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content.

(src, dst, length=None, exception=OSError, bufsize=None)

Source from the content-addressed store, hash-verified

237 return unsigned_chksum, signed_chksum
238
239def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None):
240 """Copy length bytes from fileobj src to fileobj dst.
241 If length is None, copy the entire content.
242 """
243 bufsize = bufsize or 16 * 1024
244 if length == 0:
245 return
246 if length is None:
247 shutil.copyfileobj(src, dst, bufsize)
248 return
249
250 blocks, remainder = divmod(length, bufsize)
251 for b in range(blocks):
252 buf = src.read(bufsize)
253 if len(buf) < bufsize:
254 raise exception("unexpected end of data")
255 dst.write(buf)
256
257 if remainder != 0:
258 buf = src.read(remainder)
259 if len(buf) < remainder:
260 raise exception("unexpected end of data")
261 dst.write(buf)
262 return
263
264def _safe_print(s):
265 encoding = getattr(sys.stdout, 'encoding', None)

Callers 2

addfileMethod · 0.70
makefileMethod · 0.70

Calls 3

exceptionFunction · 0.50
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected