By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Split binary file...

P: 7
Is there some simple way to split a big binary file (over 500 MBs) into the smaller parts, and after join them back to primordial original file?
May 20 '09 #1
Share this Question
Share on Google+
4 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
I split a JPEG file and successfully joined the parts with the following code:
Expand|Select|Wrap|Line Numbers
  1. fn = 'image.jpg'
  2.  
  3. # Split into 4 files
  4. f = open(fn, 'rb')
  5. data = f.read()
  6. f.close()
  7.  
  8. bytes = len(data)
  9. inc = (bytes+4)/4
  10. fileNames = []
  11. for i in range(0, bytes+1, inc):
  12.     fn1 = "file%s" % i
  13.     fileNames.append(fn1)
  14.     f = open(fn1, 'wb')
  15.     f.write(data[i:i+inc])
  16.     f.close()
  17.  
  18. new_file = 'image_joined.jpg'
  19. dataList = []
  20.  
  21. for fn in fileNames:
  22.     f = open(fn, 'rb')
  23.     dataList.append(f.read())
  24.     f.close()
  25.  
  26. f = open(new_file, 'wb')
  27. for data in dataList:
  28.     f.write(data)
  29. f.close()
May 20 '09 #2

P: 7
Thanks very much, @bvdet, I will try this code...
May 21 '09 #3

P: 7
Very useful code, works for me (even on the large files), fast and simple!
Thanks one more time...

King regards,
Stole
May 21 '09 #4

bvdet
Expert Mod 2.5K+
P: 2,851
You are welcome! I am glad it works for you.

-BV
May 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.