1
0
Fork 0

remove awaits from on entry

pull/1666/head
bethanyj28 2024-02-22 22:06:32 -05:00
parent a24b9c0184
commit 83731e6528
1 changed files with 3 additions and 12 deletions

View File

@ -72,7 +72,7 @@ export async function streamExtractExternal(
const timeout = 30 * 1000 // 30 seconds const timeout = 30 * 1000 // 30 seconds
return new Promise(async (resolve, reject) => { return new Promise((resolve, reject) => {
const timerFn = (): void => { const timerFn = (): void => {
response.message.destroy( response.message.destroy(
new Error(`Blob storage chunk did not respond in ${timeout}ms`) new Error(`Blob storage chunk did not respond in ${timeout}ms`)
@ -93,23 +93,17 @@ export async function streamExtractExternal(
reject(error) reject(error)
}) })
.pipe(unzip.Parse()) .pipe(unzip.Parse())
.on('entry', async (entry: unzip.Entry) => { .on('entry', (entry: unzip.Entry) => {
const fullPath = path.normalize(path.join(directory, entry.path)) const fullPath = path.normalize(path.join(directory, entry.path))
core.debug(`Extracting artifact entry: ${fullPath}`) core.debug(`Extracting artifact entry: ${fullPath}`)
if (entry.type === 'Directory') { if (entry.type === 'Directory') {
if (!(await exists(fullPath))) { promises.push(fs.mkdir(fullPath, {recursive: true}).then(() => {}))
await fs.mkdir(fullPath, {recursive: true})
}
entry.autodrain() entry.autodrain()
} else { } else {
if (!(await exists(path.dirname(fullPath)))) {
await fs.mkdir(path.dirname(fullPath), {recursive: true})
}
const writeStream = createWriteStream(fullPath) const writeStream = createWriteStream(fullPath)
promises.push( promises.push(
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
writeStream.on('finish', () => { writeStream.on('finish', () => {
console.log(`Finished writing ${fullPath}`)
resolve() resolve()
}) })
writeStream.on('error', reject) writeStream.on('error', reject)
@ -119,12 +113,9 @@ export async function streamExtractExternal(
} }
}) })
.on('end', async () => { .on('end', async () => {
console.log('All entries have been extracted')
clearTimeout(timer) clearTimeout(timer)
try { try {
console.log('Waiting for all write streams to finish')
await Promise.all(promises) await Promise.all(promises)
console.log('All write streams have finished')
resolve() resolve()
} catch (error) { } catch (error) {
reject(error) reject(error)