How do you create a .gz file using PHP?

This code does the trick // Name of the file we’re compressing $file = “test.txt”; // Name of the gz file we’re creating $gzfile = “test.gz”; // Open the gz file (w9 is the highest compression) $fp = gzopen ($gzfile, ‘w9’); // Compress the file gzwrite ($fp, file_get_contents($file)); // Close the gz file and we’re … Read more

How do I gzip compress a string in Python?

If you want to produce a complete gzip-compatible binary string, with the header etc, you could use gzip.GzipFile together with StringIO: try: from StringIO import StringIO # Python 2.7 except ImportError: from io import StringIO # Python 3.x import gzip out = StringIO() with gzip.GzipFile(fileobj=out, mode=”w”) as f: f.write(“This is mike number one, isn’t this … Read more

How do I enable gzip compression when using MVC3 on IIS7?

You can configure compression through your web.config file as follows: <system.webServer> <urlCompression doStaticCompression=”true” doDynamicCompression=”true” /> </system.webServer> You can find documentation of this configuration element at iis.net/ConfigReference. This is the equivalent of: Opening Internet Information Services (IIS Manager) Navigating through the tree-view on the left until you reach the virtual directory you wish to modify Selecting … Read more

How to read or parse MHTML (.mht) files in java

Frankly, I wasn’t expecting a solution in near future and was about to give up, but some how I stumbled on this page: http://en.wikipedia.org/wiki/MIME#Multipart_messages http://msdn.microsoft.com/en-us/library/ms527355%28EXCHG.10%29.aspx Although, not a very catchy in first look. But if you look carefully you will get clue. After reading this I fired up my IE and at random started saving … Read more

IOS Video Compression Swift iOS 8 corrupt video file

This answer has been completely rewritten and annotated to support Swift 4.0. Keep in mind that changing the AVFileType and presetName values allows you to tweak the final output in terms of size and quality. import AVFoundation extension ViewController: AVCaptureFileOutputRecordingDelegate { // Delegate function has been updated func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from … Read more

ZLIB Decompression – Client Side

Pako is a full and modern Zlib port. Here is a very simple example and you can work from there. Get pako.js and you can decompress byteArray like so: <html> <head> <title>Gunzipping binary gzipped string</title> <script type=”text/javascript” src=”https://stackoverflow.com/questions/4507316/pako.js”></script> <script type=”text/javascript”> // Get datastream as Array, for example: var charData = [31,139,8,0,0,0,0,0,0,3,5,193,219,13,0,16,16,4,192,86,214,151,102,52,33,110,35,66,108,226,60,218,55,147,164,238,24,173,19,143,241,18,85,27,58,203,57,46,29,25,198,34,163,193,247,106,179,134,15,50,167,173,148,48,0,0,0]; // Turn number array … Read more

Compress camera image before upload

Take a look over here: ByteArrayOutputStream to a FileBody Something along these lines should work: replace File file = new File(miFoto); ContentBody foto = new FileBody(file, “image/jpeg”); with Bitmap bmp = BitmapFactory.decodeFile(miFoto) ByteArrayOutputStream bos = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 70, bos); InputStream in = new ByteArrayInputStream(bos.toByteArray()); ContentBody foto = new InputStreamBody(in, “image/jpeg”, “filename”); If file size … Read more

Which compression method to use in PHP?

All of these can be used. There are subtle differences between the three: gzencode() uses the GZIP file format, the same as the gzip command line tool. This file format has a header containing optional metadata, DEFLATE compressed data, and footer containing a CRC32 checksum and length check. gzcompress() uses the ZLIB format. It has … Read more

HTTP request compression

It appears [Content-Encoding] is not a valid request header. That is actually not quite true. As per RFC 2616, sec 14.11, Content-Encoding is an entity header which means it can be applied on the entities of both, http responses and requests. Through the powers of multipart MIME messages, even selected parts of a request (or … Read more