Skip to content

Commit 59b045c

Browse files
authored
fix: corruption when uploading binary files to blob storage (#7760)
1 parent 79401c4 commit 59b045c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/commands/blobs/blobs-get.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const blobsGet = async (storeName: string, key: string, options: Options,
2424
let blob
2525

2626
try {
27-
blob = await store.get(key)
27+
blob = await store.get(key, { type: 'arrayBuffer' })
2828
} catch {
2929
return logAndThrowError(`Could not retrieve blob ${chalk.yellow(key)} from store ${chalk.yellow(storeName)}`)
3030
}
@@ -35,9 +35,10 @@ export const blobsGet = async (storeName: string, key: string, options: Options,
3535

3636
if (output) {
3737
const path = resolve(output)
38-
39-
await fs.writeFile(path, blob)
38+
await fs.writeFile(path, Buffer.from(blob))
4039
} else {
41-
console.log(blob)
40+
const decoder = new TextDecoder('utf-8')
41+
const str = decoder.decode(blob)
42+
console.log(str)
4243
}
4344
}

src/commands/blobs/blobs-set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ export const blobsSet = async (
2828
siteID: siteInfo.id,
2929
token: api.accessToken ?? '',
3030
})
31-
let value = valueParts.join(' ')
31+
let value: string | ArrayBuffer = valueParts.join(' ')
3232

3333
if (input) {
3434
const inputPath = resolve(input)
3535
try {
36-
value = await fs.readFile(inputPath, 'utf8')
36+
value = await fs.readFile(inputPath)
3737
} catch (error) {
3838
if (isNodeError(error) && error.code === 'ENOENT') {
3939
return logAndThrowError(

0 commit comments

Comments
 (0)