#!/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 md5 = await file.Md5(filePath);
            var time = Date.now() - start;
            console.log(`${filePath}    ${size}    ${time}ms
    md5:   ${md5}\r\n`)
        } else {
            var md5 = Encrypt({ str: filePath, method: 'md5' })
            console.log(`${filePath}    --md5-->    ${md5}\r\n`)
        }

    }
})()