How to compress an image via Javascript in the browser?

In short: Read the files using the HTML5 FileReader API with .readAsArrayBuffer Create a Blob with the file data and get its url with window.URL.createObjectURL(blob) Create new Image element and set it’s src to the file blob url Send the image to the canvas. The canvas size is set to desired output size Get the … Read more

How to create full compressed tar file using Python?

To build a .tar.gz (aka .tgz) for an entire directory tree: import tarfile import os.path def make_tarfile(output_filename, source_dir): with tarfile.open(output_filename, “w:gz”) as tar: tar.add(source_dir, arcname=os.path.basename(source_dir)) This will create a gzipped tar archive containing a single top-level folder with the same name and contents as source_dir.

Best JavaScript compressor [closed]

I recently released UglifyJS, a JavaScript compressor which is written in JavaScript (runs on the NodeJS Node.js platform, but it can be easily modified to run on any JavaScript engine, since it doesn’t need any Node.js internals). It’s a lot faster than both YUI Compressor and Google Closure, it compresses better than YUI on all … Read more

Compression/Decompression string with C#

The code to compress/decompress a string public static void CopyTo(Stream src, Stream dest) { byte[] bytes = new byte[4096]; int cnt; while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0) { dest.Write(bytes, 0, cnt); } } public static byte[] Zip(string str) { var bytes = Encoding.UTF8.GetBytes(str); using (var msi = new MemoryStream(bytes)) using (var mso = … Read more

How do I ZIP a file in C#, using no 3rd-party APIs?

How can I programatically (C#) ZIP a file (in Windows) without using any third party libraries? If using the 4.5+ Framework, there is now the ZipArchive and ZipFile classes. using (ZipArchive zip = ZipFile.Open(“test.zip”, ZipArchiveMode.Create)) { zip.CreateEntryFromFile(@”c:\something.txt”, “data/path/something.txt”); } You need to add references to: System.IO.Compression System.IO.Compression.FileSystem For .NET Core targeting net46, you need to … Read more

How can I tell if my server is serving GZipped content?

It looks like one possible answer is, unsurprisingly, curl: $ curl http://example.com/ –silent –write-out “%{size_download}\n” –output /dev/null 31032 $ curl http://example.com/ –silent -H “Accept-Encoding: gzip,deflate” –write-out “%{size_download}\n” –output /dev/null 2553 In the second case the client tells the server that it supports content encoding and you can see that the response was indeed shorter, compressed.

JavaScript implementation of Gzip [closed]

Edit There appears to be a better LZW solution that handles Unicode strings correctly at http://pieroxy.net/blog/pages/lz-string/index.html (Thanks to pieroxy in the comments). I don’t know of any gzip implementations, but the jsolait library (the site seems to have gone away) has functions for LZW compression/decompression. The code is covered under the LGPL. // LZW-compress a … Read more

Create a tar.xz in one command

Use the -J compression option for xz. And remember to man tar 🙂 tar cfJ <archive.tar.xz> <files> Edit 2015-08-10: If you’re passing the arguments to tar with dashes (ex: tar -cf as opposed to tar cf), then the -f option must come last, since it specifies the filename (thanks to @A-B-B for pointing that out!). … Read more