Created
December 13, 2015 19:03
-
-
Save anthonykasza/b90e2ca6e40c8294dbfc to your computer and use it in GitHub Desktop.
punch holes in a file
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
from StringIO import StringIO | |
import sys | |
import random | |
if len(sys.argv) != 3: | |
print "usage: hole_punch.py in_filename out_filenae" | |
exit() | |
ifname = sys.argv[1] | |
ofname = sys.argv[2] | |
with open(ifname, 'rb') as f: | |
d = StringIO(f.read()) | |
l = d.len | |
percent = 0.1 | |
holes = random.randint(0, int(d.len * percent)) | |
for i in range(0, holes): | |
d.seek( random.randint(0, d.len) ) | |
d.write('\x00') | |
d.seek(0) | |
with open(ofname, 'wb') as f: | |
f.write(d.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment