mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Use import() for zip js
This commit is contained in:
parent
f2635a5f00
commit
78174b242e
2 changed files with 47 additions and 16 deletions
|
|
@ -37,7 +37,6 @@ function callWithTimeout(timeout, func) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let zip
|
|
||||||
|
|
||||||
// https://stackoverflow.com/a/35610685/1397641
|
// https://stackoverflow.com/a/35610685/1397641
|
||||||
const arrayChangeHandler = {
|
const arrayChangeHandler = {
|
||||||
|
|
@ -64,30 +63,29 @@ export function makeObservableArray () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let zip = null
|
||||||
|
|
||||||
export default class AppFilesScanner {
|
export default class AppFilesScanner {
|
||||||
|
|
||||||
constructor( {
|
constructor( {
|
||||||
observableFilesArray,
|
observableFilesArray,
|
||||||
testResultStore
|
testResultStore,
|
||||||
|
zipModule = null
|
||||||
} ) {
|
} ) {
|
||||||
// Files to process
|
// Files to process
|
||||||
this.files = observableFilesArray
|
this.files = observableFilesArray
|
||||||
|
|
||||||
this.testResultStore = testResultStore
|
this.testResultStore = testResultStore
|
||||||
|
|
||||||
// https://gildas-lormeau.github.io/zip.js/
|
this.zipModule = zipModule
|
||||||
zip = require('@zip.js/zip.js')
|
|
||||||
|
|
||||||
// https://gildas-lormeau.github.io/zip.js/core-api.html#configuration
|
|
||||||
zip.configure({
|
|
||||||
workerScripts: true,
|
|
||||||
// workerScripts: {
|
|
||||||
// inflate: ["lib/z-worker-pako.js", "pako_inflate.min.js"]
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get zip () {
|
||||||
|
|
||||||
|
if ( this.zipModule ) return this.zipModule
|
||||||
|
|
||||||
|
return zip
|
||||||
|
}
|
||||||
|
|
||||||
isApp ( file ) {
|
isApp ( file ) {
|
||||||
|
|
||||||
|
|
@ -141,7 +139,9 @@ export default class AppFilesScanner {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
async unzipFile ( file ) {
|
async unzipFile ( file ) {
|
||||||
const fileReader = new zip.BlobReader( file.instance )//new FileReader()
|
if ( !this.zip ) throw new Error('Zip module not loaded')
|
||||||
|
|
||||||
|
const fileReader = new this.zip.BlobReader( file.instance )//new FileReader()
|
||||||
|
|
||||||
fileReader.onload = function() {
|
fileReader.onload = function() {
|
||||||
|
|
||||||
|
|
@ -171,7 +171,7 @@ export default class AppFilesScanner {
|
||||||
// console.log('fileReader', fileReader)
|
// console.log('fileReader', fileReader)
|
||||||
|
|
||||||
// https://gildas-lormeau.github.io/zip.js/core-api.html#zip-reading
|
// https://gildas-lormeau.github.io/zip.js/core-api.html#zip-reading
|
||||||
const zipReader = new zip.ZipReader( fileReader )
|
const zipReader = new this.zip.ZipReader( fileReader )
|
||||||
|
|
||||||
// zipReader.onprogress = console.log
|
// zipReader.onprogress = console.log
|
||||||
|
|
||||||
|
|
@ -429,7 +429,7 @@ export default class AppFilesScanner {
|
||||||
const infoXml = await rootInfoEntry.getData(
|
const infoXml = await rootInfoEntry.getData(
|
||||||
// writer
|
// writer
|
||||||
// https://gildas-lormeau.github.io/zip.js/core-api.html#zip-writing
|
// https://gildas-lormeau.github.io/zip.js/core-api.html#zip-writing
|
||||||
new zip.TextWriter(),
|
new this.zip.TextWriter(),
|
||||||
// options
|
// options
|
||||||
{
|
{
|
||||||
useWebWorkers: true,
|
useWebWorkers: true,
|
||||||
|
|
@ -503,7 +503,7 @@ export default class AppFilesScanner {
|
||||||
const bundleExecutableBlob = await bundleExecutable.getData(
|
const bundleExecutableBlob = await bundleExecutable.getData(
|
||||||
// writer
|
// writer
|
||||||
// https://gildas-lormeau.github.io/zip.js/core-api.html#zip-writing
|
// https://gildas-lormeau.github.io/zip.js/core-api.html#zip-writing
|
||||||
new zip.BlobWriter(),
|
new this.zip.BlobWriter(),
|
||||||
// options
|
// options
|
||||||
{
|
{
|
||||||
useWebWorkers: true
|
useWebWorkers: true
|
||||||
|
|
@ -620,4 +620,32 @@ export default class AppFilesScanner {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setupZipReader () {
|
||||||
|
// https://gildas-lormeau.github.io/zip.js/
|
||||||
|
zip = await import('@zip.js/zip.js')
|
||||||
|
|
||||||
|
// console.log( 'zip', zip )
|
||||||
|
|
||||||
|
// https://gildas-lormeau.github.io/zip.js/core-api.html#configuration
|
||||||
|
zip.configure({
|
||||||
|
workerScripts: true,
|
||||||
|
// workerScripts: {
|
||||||
|
// inflate: ["lib/z-worker-pako.js", "pako_inflate.min.js"]
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSetup () {
|
||||||
|
return this.zip === null
|
||||||
|
}
|
||||||
|
|
||||||
|
async setup () {
|
||||||
|
|
||||||
|
// Setup zip reader if not already done
|
||||||
|
if ( !this.zipModule && !zip ) {
|
||||||
|
await this.setupZipReader()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,9 @@ export default {
|
||||||
observableFilesArray: this.appsBeingScanned,
|
observableFilesArray: this.appsBeingScanned,
|
||||||
testResultStore
|
testResultStore
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Setup scanner
|
||||||
|
await this.scanner.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('fileInputChanged files', fileList)
|
// console.log('fileInputChanged files', fileList)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue