Skip to content

Instantly share code, notes, and snippets.

@KengoTODA
Created November 5, 2011 23:54
Show Gist options
  • Select an option

  • Save KengoTODA/1342218 to your computer and use it in GitHub Desktop.

Select an option

Save KengoTODA/1342218 to your computer and use it in GitHub Desktop.
var burrito = require('burrito'),
mime = require('mime'),
fs = require('fs'),
src;
src = burrito('var image = hoge.fuga.game.assets["chara1.gif"]', function (node) {
var p = node.parent(), n, fileName, fileData, mimeType;
if (!p) {
return;
}
n = p.value[0];
if (node.name === 'string' && p.name === 'sub' && n.length === 3 && n[0] === 'dot' && n[2] === 'assets') {
fileName = node.value[0];
fileData = fs.readFileSync(fileName).toString('base64');
mimeType = mime.lookup(fileName);
node.wrap('"data:' + mimeType + ';base64,' + fileData + '"');
}
});
console.log(src);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment