Пример #1
0
        public void Write(byte[] data, int pos, int len, bool finish)
        {
            byte[] srcData = Util.ExtractByteArray(data, pos, len);
            byte[] dstData = new byte[srcData.Length * 2 + 100];

            if (this.finished)
            {
                throw new ApplicationException("already finished");
            }

            zs.next_in       = srcData;
            zs.avail_in      = srcData.Length;
            zs.next_in_index = 0;

            zs.next_out       = dstData;
            zs.avail_out      = dstData.Length;
            zs.next_out_index = 0;

            if (finish)
            {
                zs.deflate(zlibConst.Z_FINISH);
            }
            else
            {
                zs.deflate(zlibConst.Z_SYNC_FLUSH);
            }

            fifo.Write(dstData, 0, dstData.Length - zs.avail_out);

            currentSize += len;

            this.crc32 = ZipUtil.Crc32Next(data, pos, len, this.crc32);

            if (finish)
            {
                this.finished = true;
                this.crc32    = ~this.crc32;

                GZipFooter f = new GZipFooter();
                f.CRC32 = this.crc32;
                f.ISIZE = (uint)(this.currentSize % 0x100000000);

                fifo.Write(Util.StructToByte(f));
            }
        }
Пример #2
0
		public void Write(byte[] data, int pos, int len, bool finish)
		{
			byte[] srcData = Util.ExtractByteArray(data, pos, len);
			byte[] dstData = new byte[srcData.Length * 2 + 100];

			if (this.finished)
			{
				throw new ApplicationException("already finished");
			}

			zs.next_in = srcData;
			zs.avail_in = srcData.Length;
			zs.next_in_index = 0;

			zs.next_out = dstData;
			zs.avail_out = dstData.Length;
			zs.next_out_index = 0;

			if (finish)
			{
				zs.deflate(zlibConst.Z_FINISH);
			}
			else
			{
				zs.deflate(zlibConst.Z_SYNC_FLUSH);
			}

			fifo.Write(dstData, 0, dstData.Length - zs.avail_out);

			currentSize += len;

			this.crc32 = ZipUtil.Crc32Next(data, pos, len, this.crc32);

			if (finish)
			{
				this.finished = true;
				this.crc32 = ~this.crc32;

				GZipFooter f = new GZipFooter();
				f.CRC32 = this.crc32;
				f.ISIZE = (uint)(this.currentSize % 0x100000000);

				fifo.Write(Util.StructToByte(f));
			}
		}