mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
web: expose streaming file decryption
This commit is contained in:
@@ -35,7 +35,6 @@ import { Base64DecoderStream } from "../utils/streams/base64-decoder-stream";
|
|||||||
import { toBlob } from "@notesnook-importer/core/dist/src/utils/stream";
|
import { toBlob } from "@notesnook-importer/core/dist/src/utils/stream";
|
||||||
import { DataFormat, SerializedKey } from "@notesnook/crypto";
|
import { DataFormat, SerializedKey } from "@notesnook/crypto";
|
||||||
import { IDataType } from "hash-wasm/dist/lib/util";
|
import { IDataType } from "hash-wasm/dist/lib/util";
|
||||||
import { IndexedDBKVStore } from "./key-value";
|
|
||||||
import FileHandle from "@notesnook/streamable-fs/dist/src/filehandle";
|
import FileHandle from "@notesnook/streamable-fs/dist/src/filehandle";
|
||||||
import {
|
import {
|
||||||
CacheStorageFileStore,
|
CacheStorageFileStore,
|
||||||
@@ -570,6 +569,15 @@ type FileMetadata = {
|
|||||||
export async function decryptFile(
|
export async function decryptFile(
|
||||||
filename: string,
|
filename: string,
|
||||||
fileMetadata: FileMetadata
|
fileMetadata: FileMetadata
|
||||||
|
) {
|
||||||
|
const stream = await streamingDecryptFile(filename, fileMetadata);
|
||||||
|
if (!stream) return false;
|
||||||
|
return await toBlob(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function streamingDecryptFile(
|
||||||
|
filename: string,
|
||||||
|
fileMetadata: FileMetadata
|
||||||
) {
|
) {
|
||||||
if (!fileMetadata) return false;
|
if (!fileMetadata) return false;
|
||||||
|
|
||||||
@@ -579,7 +587,7 @@ export async function decryptFile(
|
|||||||
const { key, iv } = fileMetadata;
|
const { key, iv } = fileMetadata;
|
||||||
|
|
||||||
const decryptionStream = await NNCrypto.createDecryptionStream(key, iv);
|
const decryptionStream = await NNCrypto.createDecryptionStream(key, iv);
|
||||||
return await toBlob(fileHandle.readable.pipeThrough(decryptionStream));
|
return fileHandle.readable.pipeThrough(decryptionStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveFile(filename: string, fileMetadata: FileMetadata) {
|
export async function saveFile(filename: string, fileMetadata: FileMetadata) {
|
||||||
|
|||||||
Reference in New Issue
Block a user