Sign in to follow this  
KeeperMustDie

Help With Files

Recommended Posts

Quote:
Original post by KeeperMustDie
I want to know how to remove data from file, for example i have file wich made from 3 blocks (A,B,C). I want to remove block B. How I can do that? Plz help!!
Most likely you'll want to read the file in to memory, remove the data in question, and then write the file back out to disk.

How to do this depends on what programming language you're using (and perhaps other factors as well).

Share this post


Link to post
Share on other sites
If you give us a specific scenario, we'll be able to answer more specifically. Do you know the size of any of the blocks or any other characteristics about the blocks like how they start or end?

Share this post


Link to post
Share on other sites
I using C++. Me too thought about read the file in to memory, but I want use another way because some blocks can be larger then 256 mb. The block starts with its name and size( Block_A 2142144 <data> Block_B 154862 <data> ).

Share this post


Link to post
Share on other sites
would it be better to keep data and the contents seperate but change the data size to a file offset. the size of the entry can be found from reading in the offset of the next block and subtracting them. If your at the end of the file, just use the filelength(f) to get the file size and subtract from that.

eg.
Index file
==========
Block_A 0
Block_B 2142144
Block_C 2297006


data file
=========
<data>
<data>
<data>

size of block b = 2297006 - 2142144 = 154862


that way you can have the Index file completely in memory and quickly search for the bit you need to delete. When you find the block you have the file offset and size of the data to remove. You can even sort these in alphabetical order and use a fast searching algorithm to improve searching speed further.

the index file would be rigid in its structure eg.

an array of..

struct INDEX_ENTRY {
char Name[28];
DWORD offset;
}; // 32 Bytes per structure.

so by getting the filelength of the Index file and dividing it by 32 will give you the number of entries so you can allocate an array to hold it in memory. You could then modify this index in memory (remove/add entries etc) and then save it to the index file again when finished.

you can also load objects quite quickly on demand (if you need to) as you can jump to the data you need quickly. reading through large files and searching can be slow as read functions are slow to complete. Best know what you want and go straight in and get it.

Id software used to (may still do, i dont know) keep data in pak files and have an index at the end of the file. The very first DWORD of the file would be the offset to this index. This isn't very easy to update though so i suggest keeping the index and data files seperate.

hope that helps

[Edited by - jrmcv on November 29, 2006 8:43:53 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this