adm-zip icon indicating copy to clipboard operation
adm-zip copied to clipboard

support await / promise when call extractAllTo mehtod

Open S112 opened this issue 2 years ago • 2 comments

I need to ensure that the extractAllTo method is completed before continuing to perform other program. Example:

const appPathTemp = join(moduleUpdatePath, DIST_MAP[moduleCode])
const zip = new AdmZip(filePath)
await zip.extractAllTo(appPathTemp)

But I find extractAllTo method not support. So how can i do? Thanks.

image

S112 avatar Jun 11 '23 05:06 S112

extractAllTo is not async. Your code should not advance unless that method is done. You can wrap that function call in another function that returns a promise and call await on that. Or use extractAllToAsync which takes a callback, and resolve your promise in the callback.

Unfortunately, when I made this 12 years ago, promises didn't exist in Javascript and now I can't just change the interface without breaking everyone's code.

cthackers avatar Jun 11 '23 08:06 cthackers

extractAllTo is not async. Your code should not advance unless that method is done. You can wrap that function call in another function that returns a promise and call await on that. Or use extractAllToAsync which takes a callback, and resolve your promise in the callback.

Unfortunately, when I made this 12 years ago, promises didn't exist in Javascript and now I can't just change the interface without breaking everyone's code.

Ok, let me try, Thanks.

S112 avatar Jun 12 '23 01:06 S112

I added await / promise support to the extractAllToAsync

you simply have to call function without callback

like:

await zip.extractAllToAsync(destination);

5saviahv avatar May 17 '24 15:05 5saviahv