ZlibStreamExample.cs is avaliable?

Aug 11, 2011 at 9:52 AM
Use ZlibStreamExample.cs ,I change a little, the code as follows:
public MemoryStream StringToMemoryStream(string s)
         {
             byte[] a = Encoding.UTF8.GetBytes(s);
             return new MemoryStream(a);
         }
         public Stream CopyStream(Stream src, Stream dest)
         {
             byte[] buffer = new byte[src.Length];
             int len = src.Read(buffer, 0, buffer.Length);
             while (len > 0)
             {
                 dest.Write(buffer, 0, len);
                 len = src.Read(buffer, 0, buffer.Length);
             }
             dest.Flush();
             return dest;
         }
        public MemoryStream Zip(string ToCompress)
        {
            MemoryStream msSinkCompressed;
            ZlibStream zOut;
            // first, compress:
            msSinkCompressed = new MemoryStream();
            zOut = new ZlibStream(msSinkCompressed, CompressionMode.Compress, CompressionLevel.BestCompression, true);
            CopyStream(StringToMemoryStream(ToCompress), zOut);
            zOut.Close();
            return msSinkCompressed;
        }
Is StringToMemoryStream have problems?  MemoryStream is NullStream ?
And then,  zOut.Close();have a Exception
So I can't get msSinkCompressed Correct.
Need help!
Hope for reply.
Thanks.
Coordinator
Aug 11, 2011 at 10:19 AM

I tried your code, it ran with no exceptions on my computer.

It seems you have included images in your post, but those images are not appearing for me.  I cannot see them.  It looks like this:

 What exception do you see?

 

Aug 11, 2011 at 1:50 PM

return new MemoryStream(a);——system.IO.stream.NullStream;

And then,  zOut.Close();have a Exception:length, “zOut.Length"引发了"system.NotSupportException"类型的异常;(this is most important, the length is exception,how I can get msSinkCompressed Correct.)

 

ps:My original meaning:

I want to use a GZipStream to compress data  is  direct string compress to zip(The zip is direct upLoad to http,so this zip is not file);

 

There is some problem,http://dotnetzip.codeplex.com/discussions/268506(this is my first question).

So I doubt my method is right.Then I want to change method,use ZlibStreamExample.cs .

Now I doubt which is suitable for my resquset?
Coordinator
Aug 11, 2011 at 1:58 PM

One thing at a time.

Post the complete stacktrace of the exception.