Extract and Explore compressed files online and securely.
- mdi-shield nothing leave
+ mdi-shield nothing
+ leave
your browser
diff --git a/composables/files-manager.ts b/composables/files-manager.ts
index 60102f2..37176b1 100644
--- a/composables/files-manager.ts
+++ b/composables/files-manager.ts
@@ -5,6 +5,7 @@ import * as Comlink from "comlink";
// @ts-expect-error typescript can't find it when query it with ?worker
import SevenZipWorker from "./worker/7zip-manager?worker";
import { SevenZipManager, iFile } from "./worker/7zip-manager";
+import mime from 'mime';
export const videoExtensions = ['mp4', 'avi', 'mov', 'mkv'];
export const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
@@ -74,8 +75,25 @@ export class FilesManager {
return await this.remoteSevenZipManager.generateBlobUrl(JSON.stringify(this.getFile(path)) as any);
}
- async getFileContent(path: string) {
+ async getFileContent(path: string, encoding: "utf8" | "binary" = "utf8") {
if (!this.remoteSevenZipManager) return;
- return await this.remoteSevenZipManager.getFileContent(JSON.stringify(this.getFile(path)) as any);
+ return await this.remoteSevenZipManager.getFileContent(JSON.stringify(this.getFile(path)) as any, encoding);
+ }
+
+ async downloadFile(path: string) {
+ if (!this.remoteSevenZipManager) return;
+
+ const file = this.getFile(path);
+ const fileContent = await this.getFileContent(path, "binary");
+ if (!file) return;
+
+ const blob = new Blob([fileContent as any], { type: mime.getType(file.extension!) || "application/octet-stream" });
+ const url = URL.createObjectURL(blob);
+
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = file.name;
+ a.click();
+
}
}
\ No newline at end of file
diff --git a/composables/worker/7zip-manager.ts b/composables/worker/7zip-manager.ts
index 579de02..40f366c 100644
--- a/composables/worker/7zip-manager.ts
+++ b/composables/worker/7zip-manager.ts
@@ -163,7 +163,7 @@ export class SevenZipManager {
}
// get content from buffer (Experimental)
- async getFileContent(file: iFile) {
+ async getFileContent(file: iFile, encoding: "utf8" | "binary" = "utf8") {
if (!this.sevenZip) return;
file = typeof file === "string" ? JSON.parse(file) : file;
@@ -172,7 +172,7 @@ export class SevenZipManager {
this.sevenZip.FS.chmod(file.path, 0o777);
// get file buffer
- const buffer = this.sevenZip.FS.readFile(file.path, { encoding: "utf8" });
+ const buffer = this.sevenZip.FS.readFile(file.path, { encoding: encoding as any });
// remove the file after extract local blob url
this.sevenZip.FS.unlink(file.path);