Skip to content

Commit 0fa9b06

Browse files
fix: stream manifest download (#657)
* fix: stream manifest download * test: update test coverage --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 185e135 commit 0fa9b06

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
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
}

test/coverage/coverage-summary.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"total": {"lines":{"total":2681,"covered":1959,"skipped":0,"pct":73.06},"statements":{"total":2701,"covered":1972,"skipped":0,"pct":73},"functions":{"total":319,"covered":242,"skipped":0,"pct":75.86},"branches":{"total":569,"covered":302,"skipped":0,"pct":53.07},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
1+
{"total": {"lines":{"total":2682,"covered":1960,"skipped":0,"pct":73.07},"statements":{"total":2702,"covered":1973,"skipped":0,"pct":73.01},"functions":{"total":319,"covered":242,"skipped":0,"pct":75.86},"branches":{"total":569,"covered":302,"skipped":0,"pct":53.07},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
22
,"/home/runner/work/swarm-cli/swarm-cli/src/application.ts": {"lines":{"total":2,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
33
,"/home/runner/work/swarm-cli/swarm-cli/src/config.ts": {"lines":{"total":31,"covered":30,"skipped":0,"pct":96.77},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":31,"covered":30,"skipped":0,"pct":96.77},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
44
,"/home/runner/work/swarm-cli/swarm-cli/src/curl.ts": {"lines":{"total":24,"covered":24,"skipped":0,"pct":100},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":25,"covered":25,"skipped":0,"pct":100},"branches":{"total":13,"covered":12,"skipped":0,"pct":92.3}}
@@ -37,7 +37,7 @@
3737
,"/home/runner/work/swarm-cli/swarm-cli/src/command/identity/show.ts": {"lines":{"total":33,"covered":27,"skipped":0,"pct":81.81},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":33,"covered":27,"skipped":0,"pct":81.81},"branches":{"total":10,"covered":4,"skipped":0,"pct":40}}
3838
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/add.ts": {"lines":{"total":39,"covered":38,"skipped":0,"pct":97.43},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":39,"covered":38,"skipped":0,"pct":97.43},"branches":{"total":11,"covered":10,"skipped":0,"pct":90.9}}
3939
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/create.ts": {"lines":{"total":17,"covered":16,"skipped":0,"pct":94.11},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":17,"covered":16,"skipped":0,"pct":94.11},"branches":{"total":1,"covered":0,"skipped":0,"pct":0}}
40-
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/download.ts": {"lines":{"total":49,"covered":48,"skipped":0,"pct":97.95},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":50,"covered":49,"skipped":0,"pct":98},"branches":{"total":20,"covered":19,"skipped":0,"pct":95}}
40+
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/download.ts": {"lines":{"total":50,"covered":49,"skipped":0,"pct":98},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":51,"covered":50,"skipped":0,"pct":98.03},"branches":{"total":20,"covered":19,"skipped":0,"pct":95}}
4141
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/index.ts": {"lines":{"total":11,"covered":11,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":11,"covered":11,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
4242
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/list.ts": {"lines":{"total":42,"covered":40,"skipped":0,"pct":95.23},"functions":{"total":5,"covered":4,"skipped":0,"pct":80},"statements":{"total":43,"covered":41,"skipped":0,"pct":95.34},"branches":{"total":10,"covered":9,"skipped":0,"pct":90}}
4343
,"/home/runner/work/swarm-cli/swarm-cli/src/command/manifest/merge.ts": {"lines":{"total":25,"covered":24,"skipped":0,"pct":96},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":25,"covered":24,"skipped":0,"pct":96},"branches":{"total":1,"covered":0,"skipped":0,"pct":0}}

0 commit comments

Comments
 (0)