概要
plunkerでlzmaやってみた。
plunkerで圧縮してダウンロードして、アップロードして解凍してみた。
写真
サンプルコード
var compression_mode = 7,
my_lzma = LZMA;
var file = document.getElementById('file');
var out = document.getElementById('out');
function loadLocalFile(e) {
var fileData = e.target.files[0];
var reader = new FileReader();
reader.onload = function() {
var asArray = new Uint8Array(reader.result);
alert(asArray);
my_lzma.decompress(asArray, function on_decompress_complete(result) {
//alert("Decompressed: " + result);
out.value = result;
}, function on_decompress_progress_update(percent) {
});
}
reader.readAsArrayBuffer(fileData);
}
file.addEventListener('change', loadLocalFile, false);
document.getElementById("go").onclick = function() {
my_lzma.compress(document.getElementById("compression_el").value, compression_mode, function on_compress_complete(result) {
alert("Compressed: " + result);
my_lzma.decompress(result, function on_decompress_complete(result) {
alert("Decompressed: " + result);
}, function on_decompress_progress_update(percent) {
document.title = "Decompressing: " + (percent * 100) + "%";
});
}, function on_compress_progress_update(percent) {
document.title = "Compressing: " + (percent * 100) + "%";
});
}
document.getElementById("go2").onclick = function() {
my_lzma.compress(document.getElementById("compression_el").value, compression_mode, function on_compress_complete(result) {
alert(result);
var asArray = new Uint8Array(result);
var blob = new Blob([asArray], {
type: "application/zip"
});
var linkText = document.createTextNode("down load link");
var a = document.createElement('a');
a.appendChild(linkText);
a.download = "hello2.txt.lzma";
a.href = URL.createObjectURL(blob);
document.body.appendChild(a);
}, function on_compress_progress_update(percent) {
});
}
成果物
以上。