Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Pull a zip file from a database and extract in memory

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #19685 |


    I have a database table that stores .zip files as binary. I want to pull each .zip file from the database and extract the contents. After i have extracted the files contained in the zip file i want to save them to a particular location. I need to do the extract bit in memory though, i don’t want to have to save the zip file some where and then extract it from there.

    I can’t seem to work out how to do it without first saving the zip file to a physical location and then extracting from there.

    Any help would be appreciated.


    Imported from legacy forums. Posted by adam2006 (had 2049 views)

    User (Old forums)
    Post count: 23064

    You can use a MemoryFile as the inner file for the ZipArchive, and then use a MemoryFolder to unzip files to memory. Then you will be able to manipulate the files in memory.


    AbstractFile memFile = new MemoryFile();
    Stream stream = memFile.OpenWrite( true );
    //use the stream.Write to get the .zip file from the database to the stream.
    //at the end, memFile will contain the .zip file.
    //e.g. :
    //const int size = 4096;
    //byte[] bytes = new byte[4096];
    //int numBytes;
    //while((numBytes = input.Read(bytes, 0, size)) > 0)
    //stream.Write(bytes, 0, numBytes);

    AbstractFolder destMemFolder = new MemoryFolder();
    ZipArchive memArchive = new ZipArchive( memFile );
    memArchive.CopyFilesTo( destMemFolder, true, true );

    This will extract all the files to the MemoryFolder. You can then loop through the folder to manipulate the files as you need. You can also extract only one file at a time, by using the filter parameter on the CopyFilesTo method, and manipulate only that file in the MemoryFolder.

    Imported from legacy forums. Posted by André (had 3058 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.