Example #1
0
        public LZipStream(Stream stream, CompressionMode mode, bool leaveOpen = false)
        {
            Mode           = mode;
            this.leaveOpen = leaveOpen;

            if (mode == CompressionMode.Decompress)
            {
                int dSize = ValidateAndReadSize(stream);
                if (dSize == 0)
                {
                    throw new IOException("Not an LZip stream");
                }
                byte[] properties = GetProperties(dSize);
                this.stream = new LzmaStream(properties, stream);
            }
            else
            {
                //default
                int dSize = 104 * 1024;
                WriteHeaderSize(stream);

                rawStream   = new CountingWritableSubStream(stream);
                this.stream = new Crc32Stream(new LzmaStream(new LzmaEncoderProperties(true, dSize), false, rawStream));
            }
        }
Example #2
0
            private Stream GetWriteStream(Stream writeStream)
            {
                this.counting = new CountingWritableSubStream(writeStream);
                Stream counting = this.counting;

                switch (this.writer.zipCompressionInfo.Compression)
                {
                case ZipCompressionMethod.BZip2:
                    return(new BZip2Stream(this.counting, CompressionMode.Compress, true, false));

                case ZipCompressionMethod.LZMA:
                {
                    this.counting.WriteByte(9);
                    this.counting.WriteByte(20);
                    this.counting.WriteByte(5);
                    this.counting.WriteByte(0);
                    LzmaStream stream2 = new LzmaStream(new LzmaEncoderProperties(!this.originalStream.CanSeek), false, this.counting);
                    this.counting.Write(stream2.Properties, 0, stream2.Properties.Length);
                    return(stream2);
                }

                case ZipCompressionMethod.PPMd:
                    this.counting.Write(this.writer.ppmdProperties.Properties, 0, 2);
                    return(new PpmdStream(this.writer.ppmdProperties, this.counting, true));

                case ZipCompressionMethod.None:
                    return(counting);

                case ZipCompressionMethod.Deflate:
                    return(new DeflateStream(this.counting, CompressionMode.Compress, this.writer.zipCompressionInfo.DeflateCompressionLevel, true));
                }
                throw new NotSupportedException("CompressionMethod: " + this.writer.zipCompressionInfo.Compression);
            }
Example #3
0
            private Stream GetWriteStream(Stream writeStream)
            {
                counting = new CountingWritableSubStream(writeStream);
                Stream output = counting;

                switch (writer.compression)
                {
                case ZipCompressionMethod.None:
                {
                    return(output);
                }

                case ZipCompressionMethod.Deflate:
                {
                    return(new System.IO.Compression.DeflateStream(counting,
                                                                   System.IO.Compression.CompressionMode.Compress, true));
                }

#if BZIP2
                case ZipCompressionMethod.BZip2:
                {
                    return(new BZip2Stream(counting, CompressionMode.Compress, true));
                }
#endif
#if LZMA
                case ZipCompressionMethod.LZMA:
                {
                    counting.WriteByte(9);
                    counting.WriteByte(20);
                    counting.WriteByte(5);
                    counting.WriteByte(0);

                    LzmaStream lzmaStream = new LzmaStream(new LzmaEncoderProperties(!originalStream.CanSeek),
                                                           false, counting);
                    counting.Write(lzmaStream.Properties, 0, lzmaStream.Properties.Length);
                    return(lzmaStream);
                }
#endif
#if PPMd
                case ZipCompressionMethod.PPMd:
                {
                    counting.Write(writer.ppmdProperties.Properties, 0, 2);
                    return(new PpmdStream(writer.ppmdProperties, counting, true));
                }
#endif
                default:
                {
                    throw new NotSupportedException("CompressionMethod: " + writer.compression);
                }
                }
            }