Skip to content

Instantly share code, notes, and snippets.

@savage69kr
Forked from SimonRichardson/jsc.hx
Created April 14, 2013 02:08
Show Gist options
  • Select an option

  • Save savage69kr/5381064 to your computer and use it in GitHub Desktop.

Select an option

Save savage69kr/5381064 to your computer and use it in GitHub Desktop.
import haxe.io.Bytes;
import haxe.io.BytesInput;
import haxe.io.BytesOutput;
import format.tools.CRC32;
import format.zip.Data;
import format.zip.Reader;
import format.zip.Tools;
import format.zip.Writer;
class Test {
static function main(){
//
// >> Assume this is already been done server side.
//
var string = "(function() {alert('hello');})();";
var bytes = Bytes.ofString(string);
var entry:Entry = {
fileName : "min.js",
fileSize : bytes.length,
fileTime : Date.now(),
compressed : false,
dataSize : 0,
data : bytes,
crc32 : CRC32.encode(bytes),
extraFields : new List()
};
var entries:List<Entry> = new List();
entries.add(entry);
var bytesOutput = new BytesOutput();
var writer = new Writer(bytesOutput);
writer.writeData(entries);
var zipfileBytes = bytesOutput.getBytes();
//
// <<
//
//
// >> Read the current file and inject it into the current scope.
//
var bytesInput = new BytesInput(zipfileBytes);
var reader = new Reader(bytesInput);
var entries:List<format.zip.Data.Entry> = reader.read();
for (entry in entries) {
if (entry.fileName.lastIndexOf('.js') == entry.fileName.length - 3) {
var string = entry.data.toString();
try {
untyped __js__('eval(string)');
} catch(e : Dynamic) {
trace(e);
}
}
}
// <<
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment