MCPcopy Index your code
hub / github.com/python/cpython / copyfileobj

Function copyfileobj

Lib/tarfile.py:234–257  ·  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

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

Callers 2

addfileMethod · 0.70
makefileMethod · 0.70

Calls 3

exceptionFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…