mailiverse/gwt/war/js/zip/test.html

113 lines
16 KiB
HTML
Raw Normal View History

2013-07-21 13:40:17 -04:00
<html>
<body>
<script>
//JSZip = { compressions : {} };
zip = {} ;
</script>
<script src="inflate.js"></script>
<script src="deflate.js"></script>
<script>
function zip_inflate(b)
{
var i, a, res, inflater;
var a = new Uint8Array(b.length);
for (i=0; i<b.length; ++i)
a[i] = b.charCodeAt(i);
var inflater = new zip.Inflater();
res = inflater.append(a);
var str = "";
for (var i=0; i<res.length; i++) {
str += String.fromCharCode(res[i])
}
return str;
}
function zip_deflate(b)
{
var i, a, res, inflater;
var a = new Uint8Array(b.length);
for (i=0; i<b.length; ++i)
a[i] = b.charCodeAt(i);
var inflater = new zip.Deflater();
inflater.append(a);
res = inflater.flush();
var str = "";
for (var i=0; i<res.length; i++) {
str += String.fromCharCode(res[i])
}
return str;
}
function test ()
{
var ref64s = [
btoa("this will work yes it will"), // but the next one won't
"AAAAAzEuMAAAAAEBAAAPfHicbZnHjuNKtkX/Jae8ePSugR7QeyPRiWz0gCJFJ3pSdI3+96e6XVRlATXMFBZOmBMRe0n/+Voe41R27dc/vuD/g77++kofWdmW89//+s9XGzeP90dj181f//3r61Wm9dc//vWvr7Rediwr5FyAGb51FmNU73i4wgDRyhzh88N9alCcE5eR+ufXXzCKoyRBEBQJQdC///rX10ER4FXGXmAFCesdNyD3KGP+QnW0DNTzvOUXgYhRLF6854lTGI3iP/G5RBiMt9MRUul1NjohreTCnrvVJn37XpQLlsuApahXPPmJvytTP+i/cZCabmak6S9y2fSWfszEog1r+aDuvtgm7XjvsIaEGhPSuxPHEJg6cdzN/FeZr/ekX643nVGdLr3K9m6AuPe6GtpTBxjdee25Gf7EaQSGCOQnTj2nFVbo2VSAalj2WyyalJEzUbppNsfTjSBZ6JwLIWUaZ3UKJvBz6YKucVWnIOsif6KUCCKJewHsldyzNJpQO78lPA1F9xeM/KqOYwT2E1dNXjEB7sIumzB3YF+2tHPjqVRzN9Ks5dq992RSO1HYPD849h7AT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Kg22X2OUHtnYPzgwX64N/0IKe6SLBe8YE5PLXsFiSj43BpbPROzBKV32emH8CXC0znTfu7HrjqNL6tcp5lwTTmceZkexyHsNa119VW1ZA2pUe9dFfy/Drgdz0g5PaFoPO2+g+cn+eqe6ZYvFPWjMESI3kmGY6vWZvJvP/g3/VAuvSPxObX7rryNQMc2iEAhU4BHYBBht+2LMDafX1HZfaMib/pgT1TmFHG2RoXXefTPIVo4fDIAf2yFDKAL++E1Sr2QjnnTfu7
];
var i;
for (i=0; i<ref64s.length; ++i)
{
var ref64 = ref64s[i];
var level
for (level=0; level<9; ++level)
{
console.log("testing level " + level);
// var zip_inflate = JSZip.compressions["DEFLATE"].uncompress;
// var zip_deflate = JSZip.compressions["DEFLATE"].compress;
// console.log(ref64);
var ref = atob(ref64);
// console.log(ref);
var zipped = zip_deflate(ref, level);
// console.log(zipped);
var unzipped = zip_inflate(zipped);
// console.log(unzipped);
var binMatches = ref == unzipped;
if (binMatches)
console.log("binary matches, yay");
else
console.log("binary doesn't match, boo");
var unzipped64 = btoa(unzipped);
// console.log(unzipped64);
var b64Matches = ref64 == unzipped64;
if (b64Matches)
console.log("b64 matches, yay");
else
console.log("b64 doesn't match, boo");
// console.log("put a break point here");
}
}
}
</script>
<body>
<button onclick="test();">click me and open the debugger</button>
</body>
</html>