Created
June 13, 2012 12:41
-
-
Save volodymyr-mykhailyk/2923826 to your computer and use it in GitHub Desktop.
JS Deflate compression procedures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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