Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4.  
  5. splitsz = 524288
  6. zerofill = True
  7.  
  8. if len(sys.argv) > 1:
  9.     baseName = sys.argv[1]
  10.     bank = 0
  11.     try:
  12.         with open(baseName, mode='rb') as InFile:
  13.             file_data = InFile.read()
  14.             sz = len(file_data)
  15.             while sz > splitsz:
  16.                 OutFile = open("%s.b%d" % (baseName, bank), "wb")
  17.                 OutFile.write(file_data[bank*splitsz:(bank+1)*splitsz])
  18.                 OutFile.close()
  19.                 bank += 1
  20.                 sz -= splitsz
  21.             if sz:
  22.                 OutFile = open("%s.b%d" % (baseName, bank), "wb")
  23.                 OutFile.write(file_data[bank*splitsz:])
  24.                 if zerofill:
  25.                     l = [0]*(splitsz - sz)
  26.                     OutFile.write(bytearray(l))
  27.                 OutFile.close()
  28.     except:
  29.         print("Cannot open file '%s'!" % (baseName))
  30. else:
  31.     print("Please give the source file name as parameter")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement