web: writeEncrypted -> writeEncryptedBase64

This commit is contained in:
Abdullah Atta
2023-03-22 09:30:12 +05:00
committed by Abdullah Atta
parent 7a773937c2
commit 29608099db

View File

@@ -98,18 +98,19 @@ async function writeEncryptedFile(file, key, hash) {
/**
* We perform 4 steps here:
* 1. We convert base64 to Uint8Array (if we get base64, that is)
* 1. We convert base64 to Uint8Array
* 2. We hash the Uint8Array.
* 3. We encrypt the Uint8Array
* 4. We save the encrypted Uint8Array
*/
async function writeEncrypted(filename, { data, type, key, mimeType }) {
if (type === "base64") data = new Uint8Array(Buffer.from(data, "base64"));
async function writeEncryptedBase64(metadata) {
const { data, key, mimeType } = metadata;
const { hash, type: hashType } = await hashBuffer(data);
if (!filename) filename = hash;
const bytes = new Uint8Array(Buffer.from(data, "base64"));
const file = new File([data.buffer], filename, {
const { hash, type: hashType } = await hashBuffer(bytes);
const file = new File([bytes.buffer], hash, {
type: mimeType || "application/octet-stream"
});
@@ -461,7 +462,7 @@ function clearFileStorage() {
}
const FS = {
writeEncrypted,
writeEncryptedBase64,
readEncrypted,
uploadFile: cancellable(uploadFile),
downloadFile: cancellable(downloadFile),