Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Zip files to another zip

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19836 |

    Hello,
    First time post.

    I can say what I’ve been asked to do and request that I be told if it is possible if someone would not mind.

    I have a zip file on disk. I have a string array with filenames to get from that zip.

    I have been asked to get them and put them in a new zip in memory without creating a new file on disk, or shall I say an In Memory zip archive if that is appropriate.

    Here is where I start to fall apart.
    Even if I do use another zip file on disk, the array of files doesn’t have a copyto method which would have me looping the list and doing a copyto on each AbstractFile. Seems like a large performance hit.

    Next, I tried to use streams for all of the files I was getting out of the original zip on disk. That was tricky but doable with the Streaming Compression package. I lost this one when I tried to figure how to put them in a new zip. I’ve been reading sample programs for hours seeing streams being compressed to other streams frequently but not to a zip.

    I tried to use QuickZip.zip() with the list of files to a new zip file on disk but I don’t think I did it right. I’ve got filenames only in my list, no paths so it wouldn’t know where to find them.

    Will it be necessary to unzip the items in my list to disk and add that list to a new zip on disk?

    Suggestions of any method would be greatly appreciated.

    Thanks
    Patrick

    Imported from legacy forums. Posted by Patrick (had 3961 views)

    Xceed Support
    Member
    Post count: 5658

    You can use your array of filenames to “filter” directly on the Zip archive. You just need to change the format of the array to a single string.

    Let’s say I have a Zip Archive containing 10 files (Test0.txt, Test1.txt,Test2.txt, Test3.txt, Test4.txt, Test5.txt, Test6.txt, Test7.txt, Test8.txt, Test9.txt).

    I only want to take 3 files (Test0.txt, Test1.txt, Test2.txt) from the archive and put them in my “Memory archive”.

    Here is a little snippet that shows how to do that:

    e.g.,
    <code>
    string[] list = new string[ 3 ] { “Test0.txt”, “Test1.txt”, “Test2.txt” };
    AbstractFile zipFile = new DiskFile( @”D:\Dump\zipArc.zip” );
    ZipArchive archive = new ZipArchive( zipFile );
    AbstractFile memoryZipFile = new MemoryFile( @”RAM:\Memory.zip” );
    ZipArchive memoryArchive = new ZipArchive( memoryZipFile );

    string filter = list[ 0 ];

    for( int i = 1; i < list.Length; i++ )
    {
    filter = filter + “|” + list[ i ];
    }

    archive.CopyFilesTo( memoryArchive, true, true, filter );
    </code>

    Imported from legacy forums. Posted by CharlesB (had 368 views)

    User (Old forums)
    Member
    Post count: 23064

    Fantastic. Works like a charm. Just one final thing and I’ll be golden…

    Now that I have the MemoryArchive, our next function will ftp it but it takes a Stream as a parameter.

    Is there an easy way to get the memoryArchive in to a stream?

    I tried this code and it fails when I try to access the “@RAM:\Memoryzip”. Says the address format is not supported. None of the ZipArchive methods point towards getting streams either. In the end I will need a Stream object, I was just testing with FileStream.

    private Stream getArchive(string zipFile)
    {
    ZipArchive zip = new ZipArchive(new DiskFile(zipFile));
    string filter = createFilter(zipFile);
    AbstractFile memoryZipFile = new MemoryFile( @”RAM:\Memory.zip” );
    ZipArchive memoryArchive = new ZipArchive( memoryZipFile );
    zip.CopyFilesTo(memoryArchive, true, true, filter);
    FileStream fs = new FileStream(@”RAM:\Memory.zip”, FileMode.Open);
    return (Stream)fs;
    }

    Many, many thanks.

    Imported from legacy forums. Posted by Patrick (had 421 views)

    User (Old forums)
    Member
    Post count: 23064

    I guess a simpler question is…

    Does
    memoryZipFile.OpenRead() get what I need?

    I believe it will but I am having trouble writing it out to disk to check if all of the correct files went in (testing purposes only).

    Thanks

    Imported from legacy forums. Posted by Patrick (had 457 views)

    Xceed Support
    Member
    Post count: 5658

    It will get you a Stream (reading stream) on the Zip Archive itself.

    Here is an other snippet that shows you can use that stream:

    e.g.,
    <code>
    using( Stream source = memoryZipFile.OpenRead() )
    {
    using( Stream destination = new MemoryStream() )
    {
    byte[] buffer = new byte[ 32768 ];
    int bytesRead = 0;
    while( ( bytesRead = source.Read( buffer, 0, buffer.Length ) ) > 0 )
    {
    destination.Write( buffer, 0, bytesRead );
    }
    }
    }
    </code>

    Imported from legacy forums. Posted by CharlesB (had 4777 views)

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