Skip to content

Instantly share code, notes, and snippets.

@volodymyr-mykhailyk
Created June 13, 2012 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save volodymyr-mykhailyk/2923826 to your computer and use it in GitHub Desktop.
Save volodymyr-mykhailyk/2923826 to your computer and use it in GitHub Desktop.
JS Deflate compression procedures
var originalString = "some data that should be compressed";
//convert string to bytes array
var originalBytes = stringToByteArray(originalString);
//generate header as byte array
var headerBytes = String.fromCharCode(120, 218);
//compress data
var compressedBytes = compress(originalBytes);
//calculate checksum
var checksumBytes = adler32(originalBytes);
//create final byte array
var resultBytes = headerBytes + compressedBytes + checksumBytes;
//convert it to base64.
var base64String = window.btoa(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment