473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Split binary file...

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
4 9684
bvdet
2,851 Expert Mod 2GB
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
Thanks very much, @bvdet, I will try this code...
May 21 '09 #3
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
2,851 Expert Mod 2GB
You are welcome! I am glad it works for you.

-BV
May 21 '09 #5

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

Similar topics

12
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
0
by: j | last post by:
Hi, Anyone out there with binary search tree experience. Working on a project due tomorrow and really stuck. We need a function that splits a binary tree into a bigger one and smaller one(for a...
14
by: Giovanni Bajo | last post by:
Hello, python24.dll is much bigger than python23.dll. This was discussed already on the newsgroup, see the thread starting here:...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
10
by: mb | last post by:
I was wondering if there is an easy, more useful Split function that will split with a string delimiter like "<>" or "////"?
4
by: Itzik | last post by:
can i split this string string str = "aa a - bb-b - ccc" with this delimiter string del = " - " i want recieve 3 items : "aa a" , "bb-b" , "ccc"
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
2
by: ownowl | last post by:
Hello beginer under python, I have a problem to get lines in a text file. lines have inside the \n (x0A) char, and le readline method split the line at this char too (not only at x0Dx0A). for...
2
by: Matt | last post by:
I have a client that transmits a file to us with many XML documents enclosed. The problem is that each is a different format and may have different encodings as they contain information from many...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.