Created
March 27, 2014 14:18
-
-
Save aesnyder/9808552 to your computer and use it in GitHub Desktop.
Remove base64 heads from array - whammy.js
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
# remove the heads off arrays of base_64 encoded datauris | |
# | |
# in this example we take the array of images encoded from | |
# whammy.js and return an array without the heads. This is | |
# an admittedly vain optimization but, every byte counts. | |
Base64Header = (type) -> | |
head: "data:#{type};base64," | |
add: (string) -> | |
"#{HEAD}#{string}" | |
remove: (string) -> | |
string.replace HEAD, '' | |
Kompressor = (type) -> | |
header = Base64Header(type) | |
compress: (frames) -> | |
frames.map header.remove | |
decompress: (frames) -> | |
frames.map header.add | |
webpKompressor = Kompressor('image/webp') | |
compressedFrames = webpKompressor.compress frames | |
uncompressedFrames = webpKompressor.decompress fames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment