Decompress stream without ZipInputStream

2 posts, 0 answers
  1. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 27 Mar 2015 Link to this post

    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
  2. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 27 Mar 2015 Link to this post

    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);
                }
            }
Back to Top