Ejemplo n.º 1
0
        private static byte[] getInputByCompress(byte[] toByteArray)
        {
            TransferInputStream fis = new TransferInputStream(toByteArray);
            int unCompressedLength  = fis.readInt();
            int compressedLength    = fis.readInt();

            byte[] input = new byte[compressedLength];
            fis.readFully(input, 0, compressedLength);

            byte[]              output       = new byte[unCompressedLength];
            MemoryStream        memoryStream = new MemoryStream(input);
            Inflater            decompresser = new Inflater();
            InflaterInputStream infis        = new InflaterInputStream(memoryStream, decompresser);

            int currentIndex = 0;
            int count        = output.Length;

            while (true)
            {
                int numRead = infis.Read(output, currentIndex, count);
                if (numRead <= 0)
                {
                    break;
                }
                currentIndex += numRead;
                count        -= numRead;
            }

            memoryStream.Close();
            infis.Close();

            return(getInputByNormal(output));
        }