Skip to content

Commit 6233a30

Browse files
committed
fix: stream manifest download
1 parent abca701 commit 6233a30

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/command/manifest/download.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MantarayNode } from '@ethersphere/bee-js'
22
import chalk from 'chalk'
3-
import fs from 'fs'
3+
import { mkdir, writeFile } from 'fs/promises'
44
import { Argument, LeafCommand, Option } from 'furious-commander'
55
import { join, parse } from 'path'
66
import { exit } from 'process'
@@ -73,9 +73,9 @@ export class Download extends RootCommand implements LeafCommand {
7373
}
7474
}
7575
const parsedForkPath = parse(node.fullPathString)
76-
const data = await this.bee.downloadData(node.targetAddress)
7776

7877
if (this.stdout) {
78+
const data = await this.bee.downloadData(node.targetAddress)
7979
process.stdout.write(data.toUtf8())
8080

8181
return
@@ -85,12 +85,14 @@ export class Download extends RootCommand implements LeafCommand {
8585
const destinationFolder = join(destination, parsedForkPath.dir)
8686

8787
if (!directoryExists(destinationFolder)) {
88-
await fs.promises.mkdir(destinationFolder, { recursive: true })
88+
await mkdir(destinationFolder, { recursive: true })
8989
}
9090

91+
const readStream = await this.bee.downloadReadableData(node.targetAddress)
92+
await writeFile(join(destination, node.fullPathString), readStream)
93+
9194
if (!this.stdout && !this.quiet && !this.curl) {
9295
process.stdout.write(' ' + chalk.green('OK') + '\n')
9396
}
94-
await fs.promises.writeFile(join(destination, node.fullPathString), data.toUint8Array())
9597
}
9698
}

0 commit comments

Comments
 (0)