asar icon indicating copy to clipboard operation
asar copied to clipboard

asar.extractFile is Sync

Open thiagorova opened this issue 5 years ago • 6 comments

So... I just lost a couple minutes with this and thought it was probably a minor accident or something.

asar.extractFile is not returning a promise or using a callback. I just checked out the imprint of the code and it seems you are calling disk.readFileSync.

(archive, filename) {
  const filesystem = disk.readFilesystemSync(archive)
  return disk.readFileSync(filesystem, filename, filesystem.getFile(filename))
}

is there a way to call extractFile Asynchronously? Thanks

thiagorova avatar Feb 26 '19 18:02 thiagorova

You can't with the current API, certainly. Given the ASAR format, how feasible is it to even implement?

malept avatar Feb 26 '19 19:02 malept

@malept You'd have to pipe the file as a stream and read the file from the correct offset as your stream encounters it. Super hard to implement correctly and probably not worth it in the big scheme of things

MarshallOfSound avatar Feb 26 '19 20:02 MarshallOfSound

Humm... i see... could you add this to the docs, then? The javascript API is not really that well documented, and that can lead to some confusion as to how it should be used. It's not really that big a deal for now anyways. Thanks!

thiagorova avatar Feb 27 '19 12:02 thiagorova

We'd be happy to review a pull request to update the API docs for asar.extractFile.

malept avatar Feb 27 '19 18:02 malept

Cool! I'll look into that when I have some free time next week.

thiagorova avatar Feb 27 '19 19:02 thiagorova

@MarshallOfSound's explanation makes sense - but that leaves me wondering how Electron's fs can read individual files out of asar files?

Unless I'm crazy, I think I've used fs.copyFileSync in Electron to copy files out of the asar.

Nantris avatar Mar 03 '21 19:03 Nantris