multihash.ts 940 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Command, flags } from '@oclif/command'
  2. import { hashFile } from '../../services/helpers/hashing'
  3. import logger from '../../services/logger'
  4. import { print } from '../../services/helpers/stdout'
  5. /**
  6. * CLI command:
  7. * Hashes the file using blake3 algorithm, convert the hash in the multihash
  8. * format.
  9. *
  10. * @remarks
  11. * Should be run only during the development.
  12. * Shell command: "dev:multihash"
  13. */
  14. export default class DevMultihash extends Command {
  15. static description = 'Creates a multihash (blake3) for a file.'
  16. static flags = {
  17. help: flags.help({ char: 'h' }),
  18. file: flags.string({
  19. char: 'f',
  20. required: true,
  21. description: 'Path for a hashing file.',
  22. }),
  23. }
  24. async run(): Promise<void> {
  25. const { flags } = this.parse(DevMultihash)
  26. logger.info(`Hashing ${flags.file} ....`)
  27. const multi = await hashFile(flags.file)
  28. logger.info(`Hash: ${multi}`)
  29. print(multi)
  30. }
  31. }