Skip to content

Instantly share code, notes, and snippets.

@aesnyder
Created March 27, 2014 14:18
Show Gist options
  • Save aesnyder/9808552 to your computer and use it in GitHub Desktop.
Save aesnyder/9808552 to your computer and use it in GitHub Desktop.
Remove base64 heads from array - whammy.js
# 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