@@ -57,23 +57,16 @@ export async function extractAndWritePackage(
5757 datasetId : number ,
5858 log : LogType ,
5959) : Promise < void > {
60- const tmpZipFile = new URL ( ` ${ datasetId } .zip`, '/tmp' ) ;
60+ const tmpZipFile = fsa . toUrl ( `/tmp/ ${ datasetId } .zip`) ;
6161 try {
6262 await fsa . write ( tmpZipFile , stream ) ;
63- const fileNames : string [ ] = [ ] ;
6463
65- const writeProms : Promise < void > [ ] = [ ] ;
66-
67- return new Promise ( ( resolve , reject ) => {
64+ await new Promise < void > ( ( resolve , reject ) => {
6865 yauzl . open ( tmpZipFile . pathname , { lazyEntries : true } , ( err , zipFile ) => {
69- if ( err ) reject ( `Failed to open zip file ${ tmpZipFile . pathname } ` ) ;
66+ if ( err ) return reject ( new Error ( `Failed to open zip file ${ tmpZipFile . pathname } ` ) ) ;
7067
7168 zipFile . once ( 'end' , ( ) => {
72- Promise . all ( writeProms )
73- . then ( ( ) => {
74- resolve ( ) ;
75- } )
76- . catch ( reject ) ;
69+ reject ( new Error ( 'Did not find geopackage entry' ) ) ;
7770 } ) ;
7871
7972 zipFile . once ( 'error' , reject ) ;
@@ -83,24 +76,26 @@ export async function extractAndWritePackage(
8376 if ( entry . fileName . endsWith ( PackageExtension ) ) {
8477 log . info ( { datasetId, path : entry . fileName , target : targetFileUri . href } , 'Ingest:Read:Start' ) ;
8578
86- if ( fileNames . includes ( entry . fileName ) ) reject ( `Duplicate export package: ${ entry . fileName } ` ) ;
87- fileNames . push ( entry . fileName ) ;
88-
8979 zipFile . openReadStream ( entry , ( err , readStream ) => {
90- if ( err ) reject ( `Failed to read zip entry ${ entry . fileName } ` ) ;
80+ if ( err ) return reject ( new Error ( `Failed to read zip entry ${ entry . fileName } ` ) ) ;
9181
9282 const gzipOut = readStream . pipe ( ht ) . pipe ( createGzip ( { level : 9 } ) ) ;
93- writeProms . push (
94- fsa . write ( targetFileUri , gzipOut , {
83+ fsa
84+ . write ( targetFileUri , gzipOut , {
9585 contentType : 'application/geopackage+vnd.sqlite3' ,
9686 contentEncoding : 'gzip' ,
97- } ) ,
98- ) ;
99-
100- zipFile . readEntry ( ) ;
87+ } )
88+ . then ( ( ) => {
89+ zipFile . close ( ) ;
90+ resolve ( ) ;
91+ } )
92+ . catch ( reject ) ;
10193 } ) ;
94+ } else {
95+ zipFile . readEntry ( ) ;
10296 }
10397 } ) ;
98+
10499 zipFile . readEntry ( ) ;
105100 } ) ;
106101 } ) ;
0 commit comments