Python: Creating a streaming gzip’d file-like?

It’s quite kludgy (self referencing, etc; just put a few minutes writing it, nothing really elegant), but it does what you want if you’re still interested in using gzip instead of zlib directly. Basically, GzipWrap is a (very limited) file-like object that produces a gzipped file out of a given iterable (e.g., a file-like object, … Read more

Why does Zipping the same content twice gives two files with different SHA1?

According to Wikipedia http://en.wikipedia.org/wiki/Zip_(file_format) seems that zip files have headers for File last modification time and File last modification date so any zip file checked into git will appear to git to have changed if the zip is rebuilt from the same content since. And it seems that there is no flag to tell it … Read more

Writing text to gzip file

mode=”wb” When writing to a file opened in binary mode, you must write bytes, not string. Encode your string using str.encode: with gzip.open(‘file.gz’, ‘wb’) as f: f.write(‘Hello world!’.encode()) mode=”wt” (found by OP) Alternatively, you can write strings to your file when you open it in the wt (explicit text) mode: with gzip.open(‘file.gz’, ‘wt’) as f: … Read more

Caching and gzip compression by htaccess

# 480 weeks <FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”> Header set Cache-Control “max-age=290304000, public” </FilesMatch> # 2 DAYS <FilesMatch “\.(xml|txt)$”> Header set Cache-Control “max-age=172800, public, must-revalidate” </FilesMatch> # 2 HOURS <FilesMatch “\.(html|htm)$”> Header set Cache-Control “max-age=7200, must-revalidate” </FilesMatch> <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* … Read more

WebAPI Gzip when returning HttpResponseMessage

Add these NuGet packages: Microsoft.AspNet.WebApi.Extensions.Compression.Server System.Net.Http.Extensions.Compression.Client Then and add one line of code to App_Start\WebApiConfig.cs: GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor())); That will do the trick! Details at: NuGet package page GitHub **Updated after comment from @JCisar Update for ASP.Net Core Nuget Package is Microsoft.AspNetCore.ResponseCompression

tech