Exemple #1
0
	public static void Main (string [] args)
	{
		if (args.Length == 0 || args.Length > 3) {
			Console.WriteLine ("Usage: zipmark FILE [ITERATIONS] [BLOCKSIZE]");
			return;
		}
	
		string filename = args [0];
		FileInfo file = new FileInfo (filename);
		if (!file.Exists) {
			Console.WriteLine ("Couldn't find file {0}", filename);
			return;
		}

		FileStream fs = file.OpenRead ();

		byte [] raw = new byte [file.Length];
		int count = fs.Read (raw, 0, (int)file.Length);
		fs.Close ();

		if (count != file.Length) {
			Console.WriteLine ("Couldn't read file {0}", filename);
			return;
		}

		Deflater def = new Deflater (Deflater.BEST_COMPRESSION, false);
		Inflater inf = new Inflater (false);

		// 1. Count deflated size

		int cooked_size = Deflate (def, raw, null);
		byte [] cooked = new byte [cooked_size];

		// 2. Deflate & Inflate

		if (args.Length > 1)
			Iterations = Int32.Parse (args [1]);
		if (args.Length > 2)
			BlockSize = Int32.Parse (args [2]);

		for (int i = 0; i < Iterations; ++ i) {
			Deflate (def, raw, cooked);
			Inflate (inf, cooked, raw);
		}

		return;
	}
Exemple #2
0
	static int Inflate (Inflater inf, byte [] src, byte [] dest)
	{
		int offset, length, remain;
	
		inf.Reset ();
		inf.SetInput (src);

		offset = 0;
		while (!inf.IsNeedingInput) {
			remain = Math.Min (dest.Length - offset, BlockSize);
			if (remain == 0)
				break;

			length = inf.Inflate (dest, offset, remain);
			offset += length;
		}

		return inf.TotalOut;
	}