Write a compressing util for gzip files The task of this challenge is as following:
Write a program that reads a file of reasonable size (let's say &lt;16 MB) from stdin or anywhere else (however you like, but must not be hardcoded), and put's the compressed output onto stdout. The output must be a valid gzip compressed file and if the compressed file runs through gunzip, it should yield exactly the same file as before.
Rules

The programming language used must be known before this competition started
The score of your program is the number of characters of the source code or the assembled program (whatever is shorter)
You're not allowed to use any kind of existing compression libraries.
Have fun!
C# (534 characters)

using System.IO;using B=System.Byte;class X{static void Main(string[]a){var f=File.ReadAllBytes(a[0]);int l=f.Length,i=0,j;var p=new uint[256];for(uint k=0,r=0;k&lt;256;r=++k){for(j=0;j&lt;8;j++)r=r&gt;&gt;1^(r&amp;1)*0xedb88320;p[k]=r;}uint c=~(uint)0,n=c;using(var o=File.Open(a[0]+".gz",FileMode.Create)){o.Write(new B[]{31,139,8,0,0,0,0,0,4,11},0,10);for(;i&lt;l;i++){o.Write(new B[]{(B)(i&lt;l-1?0:1),1,0,254,255,f[i]},0,6);c=p[(c^f[i])&amp;0xFF]^c&gt;&gt;8;}c^=n;o.Write(new[]{(B)c,(B)(c&gt;&gt;8),(B)(c&gt;&gt;16),(B)(c&gt;&gt;24),(B)l,(B)(l&gt;&gt;8),(B)(l&gt;&gt;16),(B)(l&gt;&gt;24)},0,8);}}}


Much more readable:

using System.IO;
using B = System.Byte;
class X
{
    static void Main(string[] a)
    {
        // Read file contents
        var f = File.ReadAllBytes(a[0]);
        int l = f.Length, i = 0, j;

        // Initialise table for CRC hashsum
        var p = new uint[256];
        for (uint k = 0, r = 0; k &lt; 256; r = ++k)
        {
            for (j = 0; j &lt; 8; j++)
                r = r &gt;&gt; 1 ^ (r &amp; 1) * 0xedb88320;
            p[k] = r;
        }

        uint c = ~(uint) 0, n = c;

        // Write the output file
        using (var o = File.Open(a[0] + ".gz", FileMode.Create))
        {
            // gzip header
            o.Write(new B[] { 31, 139, 8, 0, 0, 0, 0, 0, 4, 11 }, 0, 10);
            for (; i &lt; l; i++)
            {
                // deflate block header plus one byte of payload
                o.Write(new B[] { (B) (i &lt; l - 1 ? 0 : 1), 1, 0, 254, 255, f[i] }, 0, 6);
                // Compute CRC checksum
                c = p[(c ^ f[i]) &amp; 0xFF] ^ c &gt;&gt; 8;
            }
            c ^= n;
            o.Write(new[] {
                // CRC checksum
                (B) c, (B) (c &gt;&gt; 8), (B) (c &gt;&gt; 16), (B) (c &gt;&gt; 24),
                // original file size
                (B) l, (B) (l &gt;&gt; 8), (B) (l &gt;&gt; 16), (B) (l &gt;&gt; 24)
            }, 0, 8);
        }
    }
}


Comments:


Expects path to file as first command-line argument.
Output file is input file + .gz.
I am not using any libraries to do the gzip, deflate or CRC32. It’s all in there.
This “compressor” increases the filesize by a factor of 6. But it’s in valid gzip format!
Tested using GNU gunzip and WinRAR.