Last active
July 12, 2023 17:01
-
-
Save geekman/8144299d8a8788b1c76370a619bedd1a to your computer and use it in GitHub Desktop.
removes a block within a file and shifts its following contents "upwards"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# moves up file data at current pos to specified to_offset | |
def moveup(f, to_offset, block_size=4096): | |
assert f.tell() > to_offset | |
while True: | |
data = f.read(block_size) | |
newpos = f.tell() | |
f.seek(to_offset) | |
to_offset += len(data) | |
if len(data) == 0: break | |
f.write(data) | |
f.seek(newpos) | |
f.truncate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment