@ethersphere/swarm-cli
Version:
CLI tool for Bee
23 lines (19 loc) • 666 B
text/typescript
import { MerkleTree, Reference } from '@ethersphere/bee-js'
import { readFileSync } from 'fs'
import { Argument, LeafCommand } from 'furious-commander'
import { RootCommand } from './root-command'
export class Hash extends RootCommand implements LeafCommand {
public readonly name = 'hash'
public readonly description = 'Print the Swarm hash of a file'
({
key: 'path',
description: 'Path to the file',
required: true,
autocompletePath: true,
})
public path!: string
public async run(): Promise<void> {
super.init()
this.console.all(new Reference((await MerkleTree.root(readFileSync(this.path))).hash()).toHex())
}
}