11import { VirtualFileSystem } from './VirtualFileSystem'
2- import { Uint8ArrayReader , Uint8ArrayWriter , ZipReader } from '@zip.js/zip.js'
2+ import { Entry , FileEntry , Uint8ArrayReader , ZipReader } from '@zip.js/zip.js'
33import { VirtualFile } from './VirtualFile'
44import { cachePutData } from '../AssetCacheHelper'
55import { SelectFilesProgress } from '../selectfiles/SelectFilesProgress'
@@ -17,23 +17,23 @@ export class ZipFileParser {
1717 this . progress . setProgress ( `Reading ZIP file entries...` , progress , total )
1818 }
1919 } )
20- const wadEntries = zipEntries . filter ( ( e ) => ! e . directory && ! ! e . filename . match ( / . + \. w a d / i ) )
20+ const wadEntries = zipEntries . filter ( ZipFileParser . isWadFileEntry )
2121 await Promise . all ( wadEntries . map ( async ( e ) => {
2222 const lFileName = e . filename . replace ( 'Rock Raiders/' , '' ) . toLowerCase ( )
23- const buffer = ( await e . getData ?. ( new Uint8ArrayWriter ( ) , {
23+ const buffer = await e . arrayBuffer ( {
2424 onprogress : ( progress : number , total : number ) : undefined => {
2525 this . progress . setProgress ( `Extracting "${ e . filename } "...` , progress , total )
2626 }
27- } ) ) ?. buffer as ArrayBuffer // Workaround for https://github.com/gildas-lormeau/zip.js/issues/549
27+ } )
2828 if ( ! buffer ) throw new Error ( `Could not read file buffer for ${ lFileName } ` )
2929 vfs . registerFile ( VirtualFile . fromBuffer ( lFileName , buffer ) )
3030 await cachePutData ( lFileName , buffer )
3131 } ) )
32- const dataEntries = zipEntries . filter ( ( e ) => ! e . directory && ! ! e . filename . match ( / R o c k R a i d e r s \/ D a t a / i ) )
32+ const dataEntries = zipEntries . filter ( ZipFileParser . isDataFileEntry )
3333 let progress = 0
3434 await Promise . all ( dataEntries . map ( async ( e ) => {
3535 const lFileName = e . filename . replace ( 'Rock Raiders/' , '' ) . toLowerCase ( )
36- const buffer = ( await e . getData ?. ( new Uint8ArrayWriter ( ) ) ) ?. buffer as ArrayBuffer // Workaround for https://github.com/gildas-lormeau/zip.js/issues/549
36+ const buffer = await e . arrayBuffer ( )
3737 if ( ! buffer ) throw new Error ( `Could not read file buffer for ${ lFileName } ` )
3838 vfs . registerFile ( VirtualFile . fromBuffer ( lFileName , buffer ) )
3939 await cachePutData ( lFileName , buffer )
@@ -46,4 +46,12 @@ export class ZipFileParser {
4646 await zipReader . close ( )
4747 }
4848 }
49+
50+ private static isWadFileEntry ( entry : Entry ) : entry is FileEntry {
51+ return ! entry . directory && ! ! entry . filename . match ( / .+ \. w a d / i)
52+ }
53+
54+ private static isDataFileEntry ( entry : Entry ) : entry is FileEntry {
55+ return ! entry . directory && ! ! entry . filename . match ( / R o c k R a i d e r s \/ D a t a / i)
56+ }
4957}
0 commit comments