0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

plunkerでlzma

Posted at

概要

plunkerでlzmaやってみた。
plunkerで圧縮してダウンロードして、アップロードして解凍してみた。

写真

image.png

サンプルコード


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) {
    });
}


成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?