How does Google’s Page Speed lossless image compression work?

If you’re really interested in the technical details, check out the source code: png_optimizer.cc jpeg_optimizer.cc webp_optimizer.cc For PNG files, they use OptiPNG with some trial-and-error approach // we use these four combinations because different images seem to benefit from // different parameters and this combination of 4 seems to work best for a large // … Read more

How to find a good/optimal dictionary for zlib ‘setDictionary’ when processing a given set of data?

John Reiser explained on comp.compression: For the dictionary: make a histogram of short substrings, sort by payoff (number of occurrences times number of bits saved when compressed) and put the highest-payoff substrings into the dictionary. For example, if k is the length of the shortest substring that can be compressed (usually 3==k or 2==k), then … Read more

Why does BCL GZipStream (with StreamReader) not reliably detect Data Errors with CRC32?

Preface .NET [4 and previous] users should not use the Microsoft-provided GZipStream or DeflateStream classes under any circumstances, unless Microsoft replaces them completely with something that works. Use the DotNetZip library instead. Update to Preface The .NET Framework 4.5 and later have fixed the compression problem, and GZipStream and DeflateStream use zlib in those versions. … Read more

Can gzip compression be selectively disabled in ASP.NET/IIS 7?

@Aristos’ answer will work for WebForms, but with his help, I’ve adapted a solution more inline with ASP.NET/MVC methodology. Create a new filter to provide the gzipping functionality: public class GzipFilter : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { base.OnActionExecuted(filterContext); var context = filterContext.HttpContext; if (filterContext.Exception == null && context.Response.Filter != null && !filterContext.ActionDescriptor.IsDefined(typeof(NoGzipAttribute), … Read more

Using SharpZipLib to unzip specific files?

ZipFile.GetEntry should do the trick: using (var fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read)) using (var zf = new ZipFile(fs)) { var ze = zf.GetEntry(fileName); if (ze == null) { throw new ArgumentException(fileName, “not found in Zip”); } using (var s = zf.GetInputStream(ze)) { // do something with ZipInputStream } }

How can I use deflated/gzipped content with an XHR onProgress function?

A slightly more elegant variation on your solution would be to set a header like ‘x-decompressed-content-length’ or whatever in your HTTP response with the full decompressed value of the content in bytes and read it off the xhr object in your onProgress handler. Your code might look something like: request.onProgress = function (e) { var … Read more

How to Compress/Decompress tar.gz files in java

I’ve written a wrapper for commons-compress called jarchivelib that makes it easy to extract or compress from and into File objects. Example code would look like this: File archive = new File(“/home/thrau/archive.tar.gz”); File destination = new File(“/home/thrau/archive/”); Archiver archiver = ArchiverFactory.createArchiver(“tar”, “gz”); archiver.extract(archive, destination);