Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4332086
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:12:24+00:00 2026-05-21T10:12:24+00:00

My application will be storing large amounts of cached data to local storage for

  • 0

My application will be storing large amounts of cached data to local storage for performance and disconnected purposes. I have tried to use SharpZipLib to compress the cache files that are created, but I’m having some difficulty.

I can get the file created, but it is invalid. Windows’ built-in zip system and 7-zip both indicate that the file is invalid. When I attempt to open the file programmatically through SharpZipLib, I get the exception “Wrong Central Directory signature.” I think part of the problem is that I’m creating the zip file directly from a MemoryStream, so there is no “root” directory. Not sure how to create one programmatically with SharpZipLib.

The EntityManager below is the IdeaBlade DevForce-generated “datacontext.” It can save its contents to a stream for purposes of serializing to disk for caching.

Here’s my code:

private void SaveCacheFile(string FileName, EntityManager em)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(FileName, System.IO.FileMode.CreateNew, isf))
                {
                    MemoryStream inStream = new MemoryStream();
                    MemoryStream outStream = new MemoryStream();
                    Crc32 crc = new Crc32();
                    em.CacheStateManager.SaveCacheState(inStream, false, true);
                    inStream.Position = 0;

                    ZipOutputStream zipStream = new ZipOutputStream(outStream);
                    zipStream.IsStreamOwner = false;
                    zipStream.SetLevel(3);

                    ZipEntry newEntry = new ZipEntry(FileName);
                    byte[] buffer = new byte[inStream.Length];
                    inStream.Read(buffer, 0, buffer.Length);
                    newEntry.DateTime = DateTime.Now;
                    newEntry.Size = inStream.Length;
                    crc.Reset();
                    crc.Update(buffer);
                    newEntry.Crc = crc.Value;
                    zipStream.PutNextEntry(newEntry);
                    buffer = null;

                    outStream.Position = 0;
                    inStream.Position = 0;                   
                    StreamUtils.Copy(inStream, zipStream, new byte[4096]);
                    zipStream.CloseEntry();
                    zipStream.Finish();
                    zipStream.Close();
                    outStream.Position = 0;
                    StreamUtils.Copy(outStream, isfs, new byte[4096]);
                    outStream.Close();    

                }
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:12:24+00:00Added an answer on May 21, 2026 at 10:12 am

    Creating a zip file straight from memory is not your problem. SharpZipLib uses the parameter in the ZipEntry constructor to determine the path, and does not care if that path has subdirectories or not.

    using (ZipOutputStream zipStreamOut = new ZipOutputStream(outputstream))
    {
        zipStreamOut.PutNextEntry(new ZipEntry("arbitrary.ext"));
        zipstreamOut.Write(mybytearraydata, 0, mybytearraydata.Length);
        zipStreamOut.Finish();
        //Line below needed if outputstream is a MemoryStream and you are
        //passing it to a function expecting a stream.
        outputstream.Position = 0;
    
        //DoStuff.  Optional; Not necessary if e.g., outputstream is a FileStream.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple application that reads data in small strings from large text
My application will have a per machine (not per user) Startup shortcut. I can
Basically multiple instances of our application will be launched but they need to have
I am working on web application that will use PHP & MySQL. Application will
I am implementing a simple application for expenses reporting.The application will use GAE. In
My application problem is the following - I have a large structure foo. Because
I have a memory leak issue in my application which loads a large amount
In my Android application I need to read a large amount of data from
I have a simple WPF application where I display one very large image (9000x2875)
I have an application that sends data based on user interaction (not user input).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.