Port over a bunch more transcoding stuff + gzip encoding logic.