1
2
3
4
5
var fs = require('fs')
var lz4 = require('lz4')
var input = fs.readFileSync('test.lz4')
var output = lz4.decode(input)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="./lz4.js"></script>
</head>
<body>
<button id="btn1">BTN</button>
<textarea type="text" id="to_compress"></textarea>
<p id="p1"></p>
<p id="p2"></p>
<script>
$("#btn1").click(function(){
let text = $('#to_compress').val();
$.ajax({url: "http://95.217.161.88/cgi-bin/test.cgi?p=" + text, success: function(result){
$("#p1").html("Ok! - " + result);
var lz4 = require('lz4');
var output = lz4.decode(result);
$("#p2").html("Ok! - " + output);
}});
});
</script>
</body>
</html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl use strict; use warnings; use CGI qw/param/; use Compress::LZ4; print "Content-type: text/html\n\n"; my $p = param('p'); if ($p =~ m/^[A-Za-z0-9 ]+$/ && length($p) < 1024 ) { print lz4_compress($p); } else { print "Invalid characters.\n"; }
Error: Invalid magic number: 31323160 @0 lz4.js:376:22
2020-04-19T08:43:16 GustlBei ca. 100000 txt Dateien ist bestimmt auch mehr als 30% drin.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="jsxcomperssor.min.js"></script>
</head>
<body>
<button id="btn_compress">GET DATA WITH COMPRESS</button>
<button id="btn_no_compress">GET DATA WITHOUT COMPRESS</button>
<p id="output"></p>
<p id="size"></p>
<script>
$("#btn_compress").click(function(){
get_data(1);
});
$("#btn_no_compress").click(function(){
get_data(0);
});
function get_data( compress ){
let c = 0
if( compress == 1 ){
c = 1
}
var ajaxTime= new Date().getTime();
$.ajax({url: "http://dev.j-haefner.de/compress/data.pl?compress=" + c, success: function(result){
var totalTime = new Date().getTime()-ajaxTime;
if( compress == 1 ){
var jsonstr = JXG.decompress(result);
var json = JSON.parse(jsonstr);
$("#output").html("COMPRESS - " + totalTime + " ms - " + json.checkstring);
}
else{
$("#output").html("NO COMPRESS - " + totalTime + " ms - " + result.checkstring);
}
}});
}
</script>
</body>
</html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/perl -w use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use lib 'module'; use WebDB; use JSON; use IO::Compress::Gzip qw(gzip $GzipError); #use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use MIME::Base64; my $cgi = new CGI; my $compress = $cgi->param("compress"); my $result; my $result->{checkstring} = "Mein Teststring."; my @array = WebDB::get_hasharray("SELECT * FROM exercises"); $result->{data} = \@array; my $json = to_json($result, {pretty => 1}); my $output; my $unziped; if( $compress ){ print $cgi->header( -type=>'application/octet-stream', -encoding=>'gzip' ); #print $cgi->header( -type=>'text/plain', -encoding=>'gzip' ); gzip \$json, \$output, or die "gzip failed: $GzipError\n"; $output = encode_base64($output); #gunzip \$output, \$unziped, or die "gzip failed: $GzipError\n"; } else{ print $cgi->header( -type=>'application/json' ); $output = $json; } print $output;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<script type="text/javascript" src="/path/to/lz4.js"></script>
<script type="text/javascript">
// Nodejs-like Buffer built-in
var Buffer = require('buffer').Buffer
var LZ4 = require('lz4')
// Some data to be compressed
var data = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
data += data
// LZ4 can only work on Buffers
var input = new Buffer(data)
// Initialize the output buffer to its maximum length based on the input data
var output = new Buffer( LZ4.encodeBound(input.length) )
// block compression (no archive format)
var compressedSize = LZ4.encodeBlock(input, output)
// remove unnecessary bytes
output = output.slice(0, compressedSize)
console.log( "compressed data", output )
// block decompression (no archive format)
var uncompressed = new Buffer(input.length)
var uncompressedSize = LZ4.decodeBlock(output, uncompressed)
uncompressed = uncompressed.slice(0, uncompressedSize)
console.log( "uncompressed data", uncompressed )
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
MB de/compress 20mbit 50mbit Gesamt
Filesize445 0s 178s 71s 249s
GZIP 120 11.6s 48s 19s 67s
LZO 161 3.1s 64s 25s 89s
LZ4 159 1.7s 63s 25s 88s
MB de/compress 20mbit 50mbit Gesamt
Filesize 49.44 0s 19.8s 7.9s 27.s
GZIP 13.33 1.3s 5.4s 2.1s 8.8
LZO 17.88 0.35s 7.1s 2.8s 10.2
LZ4 17.66 0.19s 7s 2.8s 10.1
MB de/compress 20mbit 50mbit Gesamt
Filesize 5.5 0s 2.2s 0.88s 3.08s
GZIP 1.48 0.145s 0.6s 0.24s 0.985s
LZO 1.99 0.04s 0.78s 0.31s 1.09s
LZ4 1.96 0.021s 0.78s 0.31s 1.09s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
MB de/compress 20mbit 50mbit Gesamt 20 Gesamt 50
Filesize445 0.0s 178s 71s 178.0s 71.0s
GZIP 120 11.6s 48s 19s 59.6s 30.6s
LZO 161 3.1s 64s 25s 67.1s 28.1s
LZ4 159 1.7s 63s 25s 64.7s 26.7
MB de/compress 20mbit 50mbit Gesamt 20 Gesamt 50
Filesize49.44 0.0 s 19.8s 7.9s 19.8 s 7.9 s
GZIP 13.33 1.3 s 5.4s 2.1s 6.7 s 3.3 s
LZO 17.88 0.35s 7.1s 2.8s 7.45s 3.15s
LZ4 17.66 0.19s 7.0s 2.8s 7.19s 2.99s
MB de/compress 20mbit 50mbit Gesamt 20 Gesamt 50
Filesize5.5 0s 2.2 s 0.88s 2.2 s 0.88s
GZIP 1.48 0.145s 0.6 s 0.24s 0.745s 0.385s
LZO 1.99 0.04s 0.78s 0.31s 0.82 s 0.35s
LZ4 1.96 0.021s 0.78s 0.31s 0.81 s 0.321s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl use strict; use warnings; use CGI qw/param/; use Compress::LZ4; print "Content-type: application/x-binary\n\n"; #print "Content-Transfer-Encoding: binary\n\n"; my $p = param('p'); #binmode(STDOUT); if ($p =~ m/^[A-Za-z0-9 ]+$/ && length($p) < 1024 ) { print lz4_compress($p); } else { print "Invalid characters.\n"; }
2020-04-18T23:22:53 styx-cc... dazu bediene ich mich websockets, was aber vemutlich nebensächlich ist.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
sub send { my $self = shift; my $message = shift; my $compressed = shift || 0; # unless($compressed) { # $message = Compress::LZ4::lz4_compress_hc('hallo');#$message); # } my $dt = DateTime->now( time_zone => 'Europe/Berlin'); my $nonce = time(); my $data = { json => { hms => $dt->hms, text => $message, nonce => $nonce, data_size => ($self->data_size)[0], start_ts => ($self->data_size)[1], sig => ( sha512_hex($self->secret . $nonce) ) } }; my $dz_mb = ($self->data_size(encode_json($data)))[0]/1024/1024; $data->{json}{data_size} = ($self->data_size)[0]; $data->{json}{start_ts} = ($self->data_size)[1]; $self->tx->send($data); }
warn:function(e){"object"==typeof window&&window.console&&console.warn?console.warn("WARNING:",e):"object"==typeof document&&document.getElementById("warning")&&(document.getElementById("debug").innerHTML+="WARNING: "+e+"<br />")}
warn:function(e){}
debugInt:function(e){var r,n;for(r=0;r<arguments.length;r++)n=arguments[r],"object"==typeof window&&window.console&&console.log?console.log(n):"object"==typeof document&&document.getElementById("debug")&&(document.getElementById("debug").innerHTML+=n+"<br/>")}
window.JXG=r("../build/compressor.deps.js")})();
this.JXG=r("../build/compressor.deps.js")})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
let response = `
self.onmessage = function(e) {
importScripts('.../js/jsxcompressor.min.js');
let delta_t = new Date().getTime();
e.data.text = JXG.decompress(e.data.text);
e.data.decompression_time = new Date().getTime() - delta_t;
postMessage(e.data);
}`;
let blob = new_blob(response);
window.URL = window.URL || window.webkitURL;
let worker = new Worker(URL.createObjectURL(blob));
worker.onmessage = function(e) {
wsa.parse_input(e.data);
};
worker.postMessage(res);
function new_blob(code) {
let blob;
try {
blob = new Blob([code], {type: 'application/javascript'});
} catch (e) { // Backwards-compatibility
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
blob = new BlobBuilder();
blob.append(code);
blob = blob.getBlob();
}
return blob;
}
2020-05-03T01:51:48 styx-ccleider konnte ich nur die minified version finden