gzip
Export to CSV and Compress with GZIP in postgres
The trick is to make COPY send its output to stdout, then pipe the output through gzip: psql -c “COPY foo_table TO stdout DELIMITER ‘,’ CSV HEADER” \ | gzip > foo_table.csv.gz
how to search for a particular string from a .gz file?
You can use zgrep. Usage is similar to grep. zgrep “pattern” file.gz From the man page’s description: Zgrep invokes grep on compressed or gzipped files. All options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are … Read more
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
Decompress gzip file to specific directory [closed]
Given the fact that you have a .tar.gz file, the first way you tried, with the -C option, will work just fine: tar xvzf /dir/to/file.tar.gz -C /dir/to/output/ tar calls gzip to decompress, and then extracts the files from the tar stream. gzip can only decompress, so gunzip file.tar.gz would simply leave with the decompressed file.tar, … 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
Using csvreader against a gzipped file in Python
Use the gzip module: with gzip.open(filename, mode=”rt”) as f: reader = csv.reader(f) #…
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