1
0
Fork 0

update to use blob client over http client

vmjoseph/download-v4-client-blob
srryan 2023-12-18 17:11:14 -05:00
parent 68f22927e7
commit 571bf222ee
1 changed files with 6 additions and 11 deletions

View File

@ -17,6 +17,8 @@ import {
} from '../../generated'
import {getBackendIdsFromToken} from '../shared/util'
import {ArtifactNotFoundError} from '../shared/errors'
import {BlobClient, } from '@azure/storage-blob'
const scrubQueryParameters = (url: string): string => {
const parsed = new URL(url)
@ -38,18 +40,11 @@ async function exists(path: string): Promise<boolean> {
}
async function streamExtract(url: string, directory: string): Promise<void> {
const client = new httpClient.HttpClient(getUserAgentString())
const response = await client.get(url)
if (response.message.statusCode !== 200) {
throw new Error(
`Unexpected HTTP response from blob storage: ${response.message.statusCode} ${response.message.statusMessage}`
)
}
const blobClient = new BlobClient(url)
const response = await blobClient.download()
return new Promise((resolve, reject) => {
response.message
.pipe(unzip.Extract({path: directory}))
response.readableStreamBody?.pipe(unzip.Extract({path: directory}))
.on('close', resolve)
.on('error', reject)
})