Skip to content

Commit 78f38fa

Browse files
authored
fix: decrypt encrypted file during download (#636)
1 parent a82a598 commit 78f38fa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/command/download.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class Download extends RootCommand implements LeafCommand {
3030

3131
private async downloadData(): Promise<void> {
3232
let response: Bytes
33+
let nameOverride: string | undefined
3334

3435
if (this.manifestDownload.act) {
3536
const responseAct = await this.bee.downloadFile(this.address.hash, this.manifestDownload.destination, {
@@ -39,13 +40,19 @@ export class Download extends RootCommand implements LeafCommand {
3940
})
4041
response = responseAct.data
4142
} else {
42-
response = await this.bee.downloadData(this.address.hash, undefined)
43+
if (this.address.hash.length === 128) {
44+
const fileData = await this.bee.downloadFile(this.address.hash, undefined)
45+
nameOverride = fileData.name
46+
response = fileData.data
47+
} else {
48+
response = await this.bee.downloadData(this.address.hash, undefined)
49+
}
4350
}
4451

4552
if (this.manifestDownload.stdout) {
4653
process.stdout.write(response.toUtf8())
4754
} else {
48-
const path = this.manifestDownload.destination || this.address.hash
55+
const path = this.manifestDownload.destination || nameOverride || this.address.hash
4956
await fs.promises.writeFile(path, response.toUint8Array())
5057
}
5158
}

0 commit comments

Comments
 (0)