Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
85 lines (77 sloc) 2.677 kB
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<script src="rawinflate.js"></script>
<script src="rawdeflate.js"></script>
<script>
$ = function(id){ return document.getElementById(id) };
UTF8 = {
encode: function(s) { return unescape(encodeURIComponent(s)); },
decode: function(s) { return decodeURIComponent( escape(s)); }
};
Base64 = {
encode: function(s) { return btoa(s); },
decode: function(s) { return atob(s); }
};
var deflater = window.SharedWorker && new SharedWorker('rawdeflate.js');
if (deflater) {
deflater.port.addEventListener('message', done_deflating, false);
deflater.port.start();
} else if (window.Worker) {
deflater = new Worker('rawdeflate.js');
deflater.onmessage = done_deflating;
}
var t0;
function done_deflating(e) {
var t1 = new Date;
$('deflated').value = Base64.encode(e.data);
update_sizes(null, t1 - t0);
}
function compress(s) {
s = UTF8.encode(s);
t0 = new Date;
if (deflater) {
if (deflater.port && deflater.port.postMessage) {
deflater.port.postMessage(s);
} else {
deflater.postMessage(s);
}
} else {
setTimeout(function() {
done_deflating({ data: deflate(s) });
}, 0);
}
}
function decompress(s) {
setTimeout(function() {
var t0 = new Date;
$('inflated').value = UTF8.decode(RawDeflate.inflate(Base64.decode(s)));
var t1 = new Date;
update_sizes(t1 - t0, null);
}, 0);
}
function update_sizes(it, dt) {
var szi = $('szi'), inf = $('inflated'); it = it ? ' in '+ it +' ms' : '';
var szd = $('szd'), def = $('deflated'); dt = dt ? ' in '+ dt +' ms' : '';
szi.innerHTML = UTF8.encode(inf.value).length + it;
szd.innerHTML = Base64.decode(def.value).length + dt;
}
</script>
</head>
<body>
<h1>テスト</h1>
<p>$Id: test.html,v 0.3 2009/03/01 22:52:17 dankogai Exp dankogai $</p>
<p>Since deflate and inflate operate on octet streams, and web pages don't
necessarily keep those constraints, these tests first encode the original
uncompressed text as UTF-8 (capturing all of Unicode). Similarly, output
from the compression is shown Base64 encoded, as binary data is ugly. The
sizes shown are exactly what went into and came out of deflate/inflate.</p>
<dl>
<dt>Base64-decoded + inflated + UTF8-decoded (post-UTF8 original size: <span id="szi">0</span>):</dt>
<dd><textarea id="inflated" cols="64" rows="16" onkeyup="compress(this.value)"></textarea></dd>
<dt>Base64-encoded + deflated + UTF8-encoded (pre-Base64 compressed size: <span id="szd">0</span>):</dt>
<dd><textarea id="deflated" cols="64" rows="16" onkeyup="decompress(this.value)"></textarea></dd>
</dl>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.