The Forum is up for sale: XeNTaX Forum looking for new owner

zlib deflate/inflate help.

Coders and would-be coders alike, this is the place to talk about programming.
Post Reply
VILE
advanced
Posts: 46
Joined: Wed Mar 02, 2011 9:28 am
Been thanked: 1 time

zlib deflate/inflate help.

Post by VILE »

I wanna know how I can use zlib.dll to inflate a small stream. I feel like a complete noob, but for some reason I can't figure out how to call inflate...

I would also like to know how to call deflate and what properties I can edit (specifically what compression is used by the files with a 68 XX header).
BuC
ultra-n00b
Posts: 5
Joined: Sun Oct 17, 2010 9:35 pm

Re: zlib deflate/inflate help.

Post by BuC »

here is an example that i use in my app im developing, using Ionic.Zlib
this is splitting a file, compress each split, and rewriting the zlib header.
in my case the header is the length of the file -2 bytes.

Code: Select all

        private void compressZonePS3()
        {
            Directory.CreateDirectory("temp");
            var save = new Reader(zoneLocation, Endian.Little, 0);
            save.Position = 0;
            int count = s1 / 65536; //s1 = zoneFile.Length Converted to Int32

            for (int i = 1; i <= count; i++)
            {
                byte[] cut = save.ReadBytes(65536);
                var write = new Writer("temp\\" + i + ".dat", FileMode.OpenOrCreate);
                write.Write(ZlibStream.CompressBuffer(cut));
                write.Close();
                var writeheader = new DJsIO("temp\\" + i + ".dat", DJFileMode.Open,
                                            EndianType.BigEndian);
                long head = writeheader.Length - 2;
                string hexValue = head.ToString("X");
                writeheader.Position = 0;
                writeheader.WriteHexString(hexValue);
                writeheader.Close();
                save.Position = 65536 * i;
            }

            save.Close();

            for (int s = 1; s <= count; s++)
            {
                File.Move("temp\\" + s + ".dat", "temp\\000" + s + ".dat");
            }

            string[] tmpFiles = Directory.GetFiles("temp\\", "*.dat");
            var outputFile = new FileStream("temp\\temp.dat", FileMode.OpenOrCreate, FileAccess.Write);
            string prevFileName = "temp.dat";

            foreach (string tempFile in tmpFiles)
            {
                string fileName = Path.GetFileNameWithoutExtension(tempFile);
                string baseFileName = fileName;
                int bytesRead = 0;
                var buffer = new byte[1024];
                var inputTempFile = new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.Read);

                while ((bytesRead = inputTempFile.Read(buffer, 0, 1024)) > 0)
                    outputFile.Write(buffer, 0, bytesRead);

                inputTempFile.Close();
            }

            outputFile.Close();

            File.Copy("temp\\temp.dat", "temp.dat", true);
            Directory.Delete("temp", true);
        }
Image
VILE
advanced
Posts: 46
Joined: Wed Mar 02, 2011 9:28 am
Been thanked: 1 time

Re: zlib deflate/inflate help.

Post by VILE »

Where exactly is deflate being called? I can't see it.

EDIT: Thanks man I see it now, this is just what I needed.
Post Reply