From ff8e07e11a4ae7890a5aa98096e06f5e2ac7b3a8 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 21 Aug 2022 08:43:04 -0500 Subject: [PATCH] Add getZipFileReader method --- helpers/scanner/scan.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/helpers/scanner/scan.mjs b/helpers/scanner/scan.mjs index e6bc6de..f337e30 100644 --- a/helpers/scanner/scan.mjs +++ b/helpers/scanner/scan.mjs @@ -121,6 +121,25 @@ export class AppScan { return file } + getZipFileReader ( FileInstance ) { + // Check if file is a Blob, typically in the Browser + // otherwise convert it to a Blob, like in Node + // Both Browser and Node have Blob + // Node/Our File Polyfill references .arrayBuffer as a property + // Browser currently references .arrayBuffer as an async method + if ( FileInstance instanceof Blob ) { + return new zip.BlobReader( FileInstance ) + } + + if ( FileInstance instanceof ArrayBuffer ) { + return new zip.Uint8ArrayReader( FileInstance ) + } + + // return new zip.Uint8ArrayReader( new Uint8Array( FileInstance.arrayBuffer ) ) + // const FileBlob = FileInstance instanceof Blob ? FileInstance : new Blob( FileInstance.arrayBuffer ) + + throw new Error( 'FileInstance is not a known format' ) + } async readFileBlob ( FileInstance ) { return new Promise( async ( resolve, reject ) => {