MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / patch

Function patch

src/util/Diff.py:33–48  ·  view source on GitHub ↗
(old_f, actions)

Source from the content-addressed store, hash-verified

31
32
33def patch(old_f, actions):
34 new_f = io.BytesIO()
35 for action, param in actions:
36 if type(action) is bytes:
37 action = action.decode()
38 if action == "=": # Same lines
39 new_f.write(old_f.read(param))
40 elif action == "-": # Delete lines
41 old_f.seek(param, 1) # Seek from current position
42 continue
43 elif action == "+": # Add lines
44 for add_line in param:
45 new_f.write(add_line)
46 else:
47 raise "Unknown action: %s" % action
48 return new_f

Callers

nothing calls this directly

Calls 3

writeMethod · 0.45
readMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected