This is a migrated thread and some comments may be shown as answers.

Decompress stream without ZipInputStream

1 Answer 67 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Scott Waye asked on 27 Mar 2015, 01:39 PM
Hi,

How do you decompress a stream now that this class is obsolete?  I used to have:

        public static byte[] Decompress(byte[] settings)
        {
            using (var zippedStream = new ZipInputStream(new MemoryStream(settings)))
            {
                return ReadFully(zippedStream);
            }
        }

        public static byte[] ReadFully(System.IO.Stream input)
        {
            var buffer = new byte[16 * 1024];
            using (var ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }

Is it still ok to use CompressedStream directly and if so how do you create the CompressionSettings as the Method setter is protected?

Thanks,

Scott

1 Answer, 1 is accepted

Sort by
0
Scott Waye
Top achievements
Rank 2
Veteran
Iron
answered on 27 Mar 2015, 01:48 PM
Ok, I see.  It should be:

        public static byte[] Decompress(byte[] settings)
        {
            using (var zippedStream = new CompressedStream(new MemoryStream(settings), StreamOperationMode.Read, new DeflateSettings()))
            {
                return ReadFully(zippedStream);
            }
        }
Tags
ZipLibrary
Asked by
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Answers by
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Share this question
or