#!/usr/bin/env node

var file = require('../lib/file');
var path = require('path');
var { Encrypt } = require('../lib/crypto')

console.error = function () { }

var files = process.argv.slice(2);

if (files.length == 0) {
    console.log('必须指定一个路径/字符串')
    process.exit(0);
}

(async () => {
    for (var i = 0; i < files.length; i++) {
        var filePath = files[i]
        var isFile = await file.IsFile(filePath);
        if (isFile) {
            var stat = await file.Stat(filePath);
            var size = file.FormatSize(stat.size);
            var start = Date.now();
            var sha1 = await file.Md5(filePath, 'sha1');
            var time = Date.now() - start;
            console.log(`${filePath}    ${size}    ${time}ms
    sha1:   ${sha1}\r\n`)
        } else {
            var sha1 = Encrypt({ str: filePath, method: 'sha1' })
            console.log(`${filePath}    --sha1-->    ${sha1}\r\n`)
        }

    }
})()