Click here to Skip to main content
Click here to Skip to main content

File fixing utility

, 29 Jun 2002
Rate this:
Please Sign up or sign in to vote.
FileFixLib is a small file utility to enable precise cutting, splitting and joining of files.

Introduction

I don't know if this have ever happened to you, but if you are a dialup user like me, downloading huge files can be very time consuming.  Several times it happened while downloading a big file that my PC crashed or get a nice BSOD.  Some download managers can handle this as they have a "rollback" function to eliminate the corrupted last part of the partly downloaded file, sometimes the "rollback" setting isn't big enough and you find yourself with a 300MB+ white elephant.  In the past, I used to use a file splitting program to "split" the file up to the corrupted section, then continue downloading from that point onwards. This wasn't always very handy as sometimes the corrupted section is quite close to the start of the file and you have to practically re-download the entire file.  I landed up the other night in exactly that position and wasn't planning to download another 300MB.

The first requirement I needed was a function to "cut" a piece from the file from a specific start point to a specific end point so that I could recover the part of the file after the error. This would prove equally handy to get the 1st part of the file assuming only one corrupted section.  The Cut function was probably the hardest part, never having worked on files at byte level.  Now it looks pretty elementary, but I could not find any helpful examples and it took some time to make it work exactly like it should.

Now to explain the recovering process. For example, you have a 300MB file with 30KB corrupted at say the 150MB point.

  1. Recover 1st part, i.o.w. "cut" from 0 to 150MB less a couple bytes to make sure.
  2. Recover last part, i.o.w. "cut" from 150MB + 30KB plus a couple bytes to make sure to the end of file.
  3. Resume download on first part till past the start point of the last part.
  4. Re-"cut" 1st part from 0 to start point of last part.
  5. Finally, join the 2 parts.

Secondly, I needed a function to find all the corrupted parts of the file.

[Update: This only really works on CDs, floppy discs and with files on bad sectors] 

This is done with the Scan function. The return value from this function is an multi-dimensional integer array in the form int[x,2] where int[x,0] is start point and int[x,1] the end point of a corrupted part. This was probably the second hardest part, having to catch IOExceptions in a double while loop.

Then I created a library for these functions so I could just interface with it via a command line interface (included in zip) or a windows application.

Lastly I added a the following other helpful functions:

  • Split : to to split files into equal parts, implementation was easy as it just loops through the Cut function.
  • Join: to combine several files together.
  • Some overloads and a counter pointer incase you wanted to track progress in a Windows app or CL app.

The only problem I have it that I do not have a file that has multiple corrupted areas, but in theory it should work. Any suggestions welcome.

Hope this proves helpful, it sure did for me. At the end, I only had to re-download a couple of MB. Other uses include extracting files from a damaged CD.

Quite fun writing my first article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

leppie
Software Developer
South Africa South Africa
No Biography provided
Follow on   Twitter

Comments and Discussions

 
Questionwhy not write a downloader? Pinmemberv_srinu_26_f3-Nov-05 5:16 
GeneralHelp... PinmemberLeon11956-Jul-05 10:49 
Generalcool PinmemberTaha Zayed14-Sep-04 15:26 
cool;)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 30 Jun 2002
Article Copyright 2002 by leppie
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid