tags:

views:

51

answers:

3
class Node
{
    FooType Data; // I can save Data to file with extension .foo
    void Save()
    {
       // save Data to .foo file
    }
}

Now ,

class Graph
{
    List<Node> Nodes; 
    void Save()
    {
        foreach(Node node in Nodes)
        {
            node.Save();
        }
    }
}

Now when I invoke someGraph.Save(); then it creates Nodes.Count number of files.

I would like to appear those files as one file with extension somename.graph and be able to read it again as Nodes.

How can I do this? Is there a way to bundle files into a single different file?

+1  A: 

Use an archive format like zip.

Without external library support, you could just use .Net's serialisation mechanism to store a Dictionary<string, byte[]> (filename and data for each file) in a single file. Start here.

Marcelo Cantos
Nice. But am not allowed to use external libraries. +1 This is what I am thinking about but is there any other way?
TheMachineCharmer
What is "external" about it? It's built into the .Net framework.
Chris Dunaway
@Chris, that's probably my fault. The link I provided points to a third-party zip library. I wasn't aware that .Net has zip file support built in.
Marcelo Cantos
A: 

Or Graph.Save should pass the file stream it is using to each of the node.Save calls, so Node.Save uses the same file stream as its enclosing Graph.

ShellShock
I have no control over `Data.Save();`. It will create `somthing.foo` on disk. I want to combine those `.foo`s to one single file.
TheMachineCharmer
A: 

Can you not use the classes in the System.IO.Compression namespace? Specifically, GZipStream? This would not constitute a 3rd party library as it is built into .Net and is available from 2.0 and onward.

Chris Dunaway