11import { MantarayNode } from '@ethersphere/bee-js'
22import chalk from 'chalk'
3- import fs from 'fs'
3+ import { mkdir , writeFile } from 'fs/promises '
44import { Argument , LeafCommand , Option } from 'furious-commander'
55import { join , parse } from 'path'
66import { 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