init the awkward code

This commit is contained in:
Bao Nguyen
2023-02-13 19:32:10 +07:00
commit 27170afcac
5426 changed files with 1244579 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<title>test webworker</title>
</head>
<body>
<input type="file" id="file" />
<script type="module" >
function hex(buffer) {
const hexCodes = [];
const view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
const value = view.getUint32(i)
const stringValue = value.toString(16)
const padding = '00000000'
const paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function getChecksum(file){
return new Promise((resolve,reject) => {
try{
const reader = new FileReader();
reader.onload = function() {
crypto.subtle.digest("SHA-256", reader.result).then(function (hash) {
resolve(hex(hash));
});
}
reader.readAsArrayBuffer(file);
}catch(err){
reject(err);
}
});
}
function finish(){
const d = document.createElement('div');
d.setAttribute('id','done');
d.textContent = 'Done.';
document.body.appendChild(d);
}
async function fileChecksums(obj){
for( const [key,val] of Object.entries(obj) ){
obj[key] = val instanceof File ?
await getChecksum(val) : await fileChecksums(val);
}
return obj;
}
import {Archive} from '../../src/libarchive.js';
Archive.init({
workerUrl: '../../dist/worker-bundle.js'
});
window.Archive = Archive;
document.getElementById('file').addEventListener('change', async (e) => {
let obj = null, encEntries = false;
try{
const file = e.currentTarget.files[0];
const archive = await Archive.open(file);
encEntries = await archive.hasEncryptedData();
await archive.usePassword("nika");
obj = await archive.extractFiles();
obj = await fileChecksums(obj);
}catch(err){
console.error(err);
}finally{
window.obj = {files: obj, encrypted: encEntries};
finish();
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<title>test webworker</title>
</head>
<body>
<input type="file" id="file" />
<script type="module" >
function hex(buffer) {
const hexCodes = [];
const view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
const value = view.getUint32(i)
const stringValue = value.toString(16)
const padding = '00000000'
const paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function getChecksum(file){
return new Promise((resolve,reject) => {
try{
const reader = new FileReader();
reader.onload = function() {
crypto.subtle.digest("SHA-256", reader.result).then(function (hash) {
resolve(hex(hash));
});
}
reader.readAsArrayBuffer(file);
}catch(err){
reject(err);
}
});
}
function finish(){
const d = document.createElement('div');
d.setAttribute('id','done');
d.textContent = 'Done.';
document.body.appendChild(d);
}
async function fileChecksums(obj){
for( const [key,val] of Object.entries(obj) ){
obj[key] = val instanceof File ?
await getChecksum(val) : await fileChecksums(val);
}
return obj;
}
import {Archive} from '../../src/libarchive.js';
Archive.init({
workerUrl: '../../dist/worker-bundle.js'
});
window.Archive = Archive;
document.getElementById('file').addEventListener('change', async (e) => {
let obj = null;
try{
const file = e.currentTarget.files[0];
const archive = await Archive.open(file);
//console.log( await archive.getFilesObject() );
//console.log( await archive.getFilesArray() );
obj = await archive.extractFiles();
//console.log( await archive.getFilesObject() );
//console.log( await archive.getFilesArray() );
obj = await fileChecksums(obj);
}catch(err){
console.error(err);
}finally{
window.obj = obj;
finish();
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html>
<head>
<title>test webworker</title>
</head>
<body>
<input type="file" id="file" />
<script type="module" >
function hex(buffer) {
const hexCodes = [];
const view = new DataView(buffer);
for (let i = 0; i < view.byteLength; i += 4) {
const value = view.getUint32(i)
const stringValue = value.toString(16)
const padding = '00000000'
const paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function getChecksum(file){
return new Promise((resolve,reject) => {
try{
const reader = new FileReader();
reader.onload = function() {
crypto.subtle.digest("SHA-256", reader.result).then(function (hash) {
resolve(hex(hash));
});
}
reader.readAsArrayBuffer(file);
}catch(err){
reject(err);
}
});
}
function finish(){
const d = document.createElement('div');
d.setAttribute('id','done');
d.textContent = 'Done.';
document.body.appendChild(d);
}
async function fileChecksums(obj){
for( const [key,val] of Object.entries(obj) ){
obj[key] = val instanceof File ?
await getChecksum(val) : await fileChecksums(val);
}
return obj;
}
import {Archive} from '../../src/libarchive.js';
Archive.init({
workerUrl: '../../dist/worker-bundle.js'
});
window.Archive = Archive;
document.getElementById('file').addEventListener('change', async (e) => {
let objAfter,objBefore,fileObj;
try{
const file = e.currentTarget.files[0];
const archive = await Archive.open(file);
const files = await archive.getFilesArray();
fileObj = await files[0].file.extract();
}catch(err){
console.error(err);
}finally{
window.obj = await getChecksum(fileObj);
finish();
}
});
</script>
</body>
</html>