MCPcopy Create free account
hub / github.com/wal-e/wal-e / copyfileobj

Function copyfileobj

wal_e/copyfileobj.py:6–31  ·  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

4
5
6def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None):
7 """Copy length bytes from fileobj src to fileobj dst.
8 If length is None, copy the entire content.
9 """
10 if bufsize is None:
11 bufsize = pipebuf.PIPE_BUF_BYTES
12
13 if length == 0:
14 return
15 if length is None:
16 shutil.copyfileobj(src, dst, bufsize)
17 return
18
19 blocks, remainder = divmod(length, bufsize)
20 for b in range(blocks):
21 buf = src.read(bufsize)
22 if len(buf) < bufsize:
23 raise exception("unexpected end of data")
24 dst.write(buf)
25
26 if remainder != 0:
27 buf = src.read(remainder)
28 if len(buf) < remainder:
29 raise exception("unexpected end of data")
30 dst.write(buf)
31 return

Callers

nothing calls this directly

Calls 2

writeMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected