renamed to ProcessFileObject()

This commit is contained in:
ReznoRMichael 2021-01-23 01:26:16 +01:00
parent 49d275c1bc
commit 1a87c72eb8

View file

@ -30,20 +30,18 @@ function LoadSaveFile(input) {
// readAsArrayBuffer(file) // readAsArrayBuffer(file)
inputReader.readAsArrayBuffer(inputFileObject); inputReader.readAsArrayBuffer(inputFileObject);
// addEventListener("load", function) - to decode the file when loaded // addEventListener("load", function) - to decode the file when loaded
inputReader.addEventListener("load", FileObjectToArrayBuffer); inputReader.addEventListener("load", ProcessFileObject);
// 2. Decode file // 2. Decode file
// Convert ArrayBuffer to string/text TextDecoder().decode(ArrayBuffer)
// 3. Convert file to JSON string (optional?) // 3. Convert file to JSON string (optional?)
// JSON.stringify(JSON.parse(decrypted), undefined, 2) // JSON.stringify(JSON.parse(decrypted), undefined, 2)
// 4. Paste decoded string file to text area // 4. Paste decoded string file to text area
} }
// reads the File object as an Array Buffer // reads the File object as an Array Buffer and does all other operations (decoding, decryption, conversion to string, pasting to text area)
function FileObjectToArrayBuffer() { function ProcessFileObject() {
let inputArrayBuffer = this.result; let inputArrayBuffer = this.result;
try { try {
@ -63,6 +61,9 @@ function FileObjectToArrayBuffer() {
// AES decryption (ECB) removes pkcs7 padding (ArrayBuffer) // AES decryption (ECB) removes pkcs7 padding (ArrayBuffer)
inputArrayBuffer = AESDecryption(inputArrayBuffer); inputArrayBuffer = AESDecryption(inputArrayBuffer);
// Convert ArrayBuffer to string/text TextDecoder().decode(ArrayBuffer)
alert(`Array Buffer: ${inputArrayBuffer}`); alert(`Array Buffer: ${inputArrayBuffer}`);
} catch (error) { } catch (error) {
alert(`The file cannot be decoded. Error: ${error}`); alert(`The file cannot be decoded. Error: ${error}`);