zlib seems to be exactly what you want: