0

I am trying to use archive.extractFiles function to get path and file. This function is not waiting for list array to populate, instead immediately returning empty array.

    import {Archive} from 'libarchive.js/main.js';

    
    Archive.init({
            workerUrl: '/libarchive.js/dist/worker-bundle.js'
        });
    
    public async getFileAndPath(fileList) {
    const list = [];
    console.log(fileList);
    const archive = await Archive.open(fileList);
    await archive.extractFiles(async entry => {
   

     console.log(entry);
        list.push(entry);
    });
        // console.log(obj);
        return list;
    }

    How to make this function wait inside extractFiles.
      
    
ravi yadav
  • 1
  • 1
  • 2

1 Answers1

0

I believe callback function shouldn't be async you should just do

await archive.extractFiles(entry => {
    console.log(entry);
    list.push(entry);
});

BTW if you need entire array you could just use

return await archive.getFilesArray();
MySqlError
  • 620
  • 8
  • 20