MCPcopy
hub / github.com/borgbackup/borg / iter_separated

Function iter_separated

src/borg/helpers/misc.py:176–190  ·  view source on GitHub ↗

Iterate over chunks of the open file ``fd`` delimited by ``sep``. Does not trim.

(fd, sep=None, read_size=4096)

Source from the content-addressed store, hash-verified

174
175
176def iter_separated(fd, sep=None, read_size=4096):
177 """Iterate over chunks of the open file ``fd`` delimited by ``sep``. Does not trim."""
178 buf = fd.read(read_size)
179 is_str = isinstance(buf, str)
180 part = "" if is_str else b""
181 sep = sep or ("\n" if is_str else b"\n")
182 while len(buf) > 0:
183 part2, *items = buf.split(sep)
184 *full, part = (part + part2, *items) # type: ignore
185 yield from full
186 buf = fd.read(read_size)
187 # won't yield an empty part if stream ended with `sep`
188 # or if there was no data before EOF
189 if len(part) > 0: # type: ignore[arg-type]
190 yield part

Callers 2

create_innerMethod · 0.85
test_iter_separatedFunction · 0.85

Calls 1

readMethod · 0.45

Tested by 1

test_iter_separatedFunction · 0.68