Ejemplo n.º 1
0
		/// <exception cref="System.IO.IOException"></exception>
		private byte[] CompressPackFormat(int type, byte[] data)
		{
			byte[] hdr = new byte[64];
			int rawLength = data.Length;
			int nextLength = (int)(((uint)rawLength) >> 4);
			hdr[0] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked((int
				)(0x00))) | (type << 4) | (rawLength & unchecked((int)(0x0F)))));
			rawLength = nextLength;
			int n = 1;
			while (rawLength > 0)
			{
				nextLength = (int)(((uint)nextLength) >> 7);
				hdr[n++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
					(int)(0x00))) | (rawLength & unchecked((int)(0x7F)))));
				rawLength = nextLength;
			}
			ByteArrayOutputStream @out = new ByteArrayOutputStream();
			@out.Write(hdr, 0, n);
			DeflaterOutputStream d = new DeflaterOutputStream(@out);
			d.Write(data);
			d.Finish();
			return @out.ToByteArray();
		}
Ejemplo n.º 2
0
		/// <exception cref="System.IO.IOException"></exception>
		private byte[] CompressStandardFormat(string type, string length, byte[] data)
		{
			ByteArrayOutputStream @out = new ByteArrayOutputStream();
			DeflaterOutputStream d = new DeflaterOutputStream(@out);
			d.Write(Constants.EncodeASCII(type));
			d.Write(' ');
			d.Write(Constants.EncodeASCII(length));
			d.Write(0);
			d.Write(data);
			d.Finish();
			return @out.ToByteArray();
		}