diff --git a/.gitignore b/.gitignore index be32f77..745d415 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /files -*.log \ No newline at end of file +*.log +/counter.txt \ No newline at end of file diff --git a/huffman.py b/huffman.py index 676e7ed..bd8072a 100644 --- a/huffman.py +++ b/huffman.py @@ -32,7 +32,8 @@ def huffman(data): units[c] += 1 else: units[c] = 1 - units, codes = sorted([([u], units[u]) for u in units], key=lambda u: u[1]), dict.fromkeys(units.keys(), '') + codes = dict.fromkeys(units.keys(), '') + units = sorted([([u], units[u]) for u in units], key=lambda u: u[1]) while units: # creating Haffman table if len(units) > 2: @@ -53,7 +54,7 @@ def huffman(data): return codes -def tbl(table): +def nanako_encode(table): table = ';'.join([f'{k};{table[k]}' for k in table]).split(';') byts = [] for i in range(len(table)): @@ -69,7 +70,7 @@ def tbl(table): return byts -def detbl(byts): +def nanako_decode(byts): dec = [] table = {} stack = '' @@ -95,7 +96,7 @@ def compress_file(filename): log.log(f'Original size: {len(data)} bytes.') log.log('Creating Huffman table...') hf = huffman(data) - table = tbl(hf) + table = nanako_encode(hf) log.log('Embedding Huffman table...') out = [] ln = bin(len(table))[2:] # embed the table @@ -139,7 +140,7 @@ def decompress_file(filename): break i += 1 del data[:i + 2] - table = detbl(data[:int(ln, 2)]) + table = nanako_decode(data[:int(ln, 2)]) del data[:int(ln, 2)] data = ''.join(data) stack = '' diff --git a/huffpress.php b/huffpress.php index 1172db7..0ac34d8 100644 --- a/huffpress.php +++ b/huffpress.php @@ -1,12 +1,17 @@ \ No newline at end of file diff --git a/index.html b/index.html index ddb3b8c..4c62493 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ crossorigin="anonymous" /> - +
@@ -20,12 +20,7 @@

Compress your files with the Huffman compression!

-
+
+
diff --git a/script.js b/script.js index 93462b4..9dd6e39 100644 --- a/script.js +++ b/script.js @@ -1,55 +1,55 @@ function winsize() { if ( - (!toggled && $(window).width() / $(window).height() > 90 / 31) || - (toggled && $(window).width() / ($(window).height() - 219) > 18 / 7) + (!toggled && $(window).width() / $(window).height() > 90/31) || + (toggled && $(window).width() / ($(window).height()-219) > 18/7) ) { - $('body').css('justify-content', 'flex-start') + $('body').css('justify-content', 'flex-start'); } else { - $('body').css('justify-content', 'center') + $('body').css('justify-content', 'center'); } -} -window.onload = function () { +}; +$(window).on('load', function () { setTimeout(() => { - $('main').slideDown(500) - }, 100) - winsize() -} + $('main').slideDown(500); + }, 100); + winsize(); +}); $(window).on('resize', function () { - winsize() -}) + winsize(); +}); -var toggled = false +var toggled = false; $('h2').click(function () { - var time = 300 + var time = 300; if (toggled) { - $('form').slideUp(time) - $('main').css('min-height', '9vw') + $('form').slideUp(time); + $('main').css('min-height', '9vw'); setTimeout(() => { - $('h2').css('border-bottom', '0') - }, time) - toggled = false - winsize() + $('h2').css('border-bottom', '0'); + }, time); + toggled = false; + winsize(); } else { - $('main').css('min-height', 'calc(9vw + 260px)') - $('form').slideDown(time) - $('form').css('display', 'flex') - $('h2').css('border-bottom', '1px solid black') - toggled = true + $('main').css('min-height', 'calc(9vw + 260px)'); + $('form').slideDown(time); + $('form').css('display', 'flex'); + $('h2').css('border-bottom', '1px solid black'); + toggled = true; setTimeout(() => { - winsize() - }, time) - } -}) + winsize(); + }, time); + }; +}); $('form').on('submit', function submit(e) { - e.preventDefault() - $('.wrap').css('display', 'flex') - $('.process').css('display', 'block') - var form = new FormData() - form.append('mode', $('#mode').val()) + e.preventDefault(); + $('.wrap').css('display', 'flex'); + $('.process').css('display', 'block'); + var form = new FormData(); + form.append('mode', $('#mode').val()); $.each($('#file')[0].files, function (i, file) { - form.append('file', file) - }) + form.append('file', file); + }); $.ajax({ url: 'huffpress.php', type: 'POST', @@ -58,7 +58,6 @@ $('form').on('submit', function submit(e) { dataType: 'json', data: form, success: function (resp) { - console.log(resp) if (resp.status) { $('.process').css('display', 'none') $('.complete').css('display', 'block') @@ -75,14 +74,14 @@ $('form').on('submit', function submit(e) { } else { $('.process').css('display', 'none') $('.error').css('display', 'block') - } + }; }, - }) -}) + }); +}); $('.closebtn').click(function () { - $('.wrap').css('display', 'none') - $('.process').css('display', 'none') - $('.error').css('display', 'none') - $('.complete').css('display', 'none') -}) + $('.wrap').css('display', 'none'); + $('.process').css('display', 'none'); + $('.error').css('display', 'none'); + $('.complete').css('display', 'none'); +}); \ No newline at end of file