in reply to Re^2: pack/unpack binary editing
in thread pack/unpack binary editing
Hmm. Then you have a problem that will require a little more effort. How will you determine which bits to throw away?
If you can do it whilst moving through the file in a single direction, or if you can construct a set of "editing instruction" ("delete bit3/byte 700004", "insert '010' at bit6 of byte 3002" etc.), whilst treating the file read-only, then sort those into byte/bit sequence.
You can then do the editing in a second linear pass through the file. You would keep a running buffer ( 0 - 7 bits ) of any odd bits. Appending those to the front of each buffer as you read it in, make any modification to that chunk of bits and then write int( bits--in-memory/8) bytes back out, retaining the leftover bits. Rince and repeat till done.
The problem with that is that when you re-order the editing instructions, you will need to acount for any shifts in byte/bit positions in order to account for teh effects of editing that will be done by earlier sequences. Not a hugely onorous task, but one that would need thourough testing on small files before you starting screwing with the big one.
It really depends on your answer to the question I posed first. How will the sequence of edits be determined. The answer to that will define the best strategy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: pack/unpack binary editing
by tperdue (Sexton) on Feb 08, 2005 at 14:22 UTC | |
by samizdat (Vicar) on Feb 08, 2005 at 15:24 UTC | |
by BrowserUk (Patriarch) on Feb 08, 2005 at 17:04 UTC | |
by tperdue (Sexton) on Feb 10, 2005 at 12:40 UTC | |
by BrowserUk (Patriarch) on Feb 10, 2005 at 14:10 UTC | |
by tperdue (Sexton) on Feb 10, 2005 at 14:17 UTC | |
|