What / Why
I write nodejs scripts, one creates tar.gz archive, another one extracts it
Tooke me a while to get list of files from tar, I just want to await and get list
Example
I end up with following code, which looks weird but seems works
And I reading docs attentievly but couldn't get this way, until I see into code of node-tar
const listArchiveFiles = (archiveFileName) => {
return new Promise((resolve, reject) => {
let fileNames = []
try {
await tar.t({
file: path.join(basePath, archiveFileName),
cwd: basePath,
onentry: (entry) => {
// also for some reason typescript saying entry.path is a number, not a string
fileNames.push(path.basename(entry.header.path))
}
resolve(fileNames)
})
} catch (error) {
reject(error)
}
})
}
Also, docs saying tar.t return event emitter, which is not true, either promise version or callback one returns undefined, callback provides only error argument. onentry triggered on files read, but according to docs there no end event, so there no way of knowing wether files still read or already finished. If I add sizes of each entry sum is less than whole archive size, of course.Initially I was hoping that there way to make tar.x to output list of files from the archive, but it is not working that way.
So I would like to ask to update docs with this example, update on what returned from tar.t and fix typescript.
What / Why
I write nodejs scripts, one creates tar.gz archive, another one extracts it
Tooke me a while to get list of files from tar, I just want to await and get list
Example
I end up with following code, which looks weird but seems works
And I reading docs attentievly but couldn't get this way, until I see into code of node-tar
Also, docs saying tar.t return event emitter, which is not true, either promise version or callback one returns undefined, callback provides only error argument. onentry triggered on files read, but according to docs there no end event, so there no way of knowing wether files still read or already finished. If I add sizes of each entry sum is less than whole archive size, of course.Initially I was hoping that there way to make tar.x to output list of files from the archive, but it is not working that way.
So I would like to ask to update docs with this example, update on what returned from tar.t and fix typescript.