From f26091f81cae68fa3aa822570617c228d4a0eff4 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 17 Jul 2024 12:21:49 +0800 Subject: [PATCH] fixed fs --- package.json | 2 +- src/index.js | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 6692fb0..39a3611 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crypto.js", - "version": "3.2.1", + "version": "3.2.2", "description": "原生crypto加密模块的二次封装,简化常用加密函数的使用", "keywords": [ "md5", diff --git a/src/index.js b/src/index.js index 230bf0e..ea46066 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,7 @@ const MAC = (function (ns) { return Math.random().toString(16).slice(-4) })(os.networkInterfaces()) -var __inc__ = 4096 +let __inc__ = 4096 /** * [base64encode base64编码] @@ -35,7 +35,7 @@ var __inc__ = 4096 * @param {bool} urlFriendly [是否对URL友好, 默认否, 是则会把+转成-, /转成_] */ export function base64encode(str, urlFriendly) { - var buf, str64 + let buf, str64 if (Buffer.isBuffer(str)) { buf = str @@ -86,8 +86,8 @@ export function rand(len, forceNum) { // 返回一个如下格式的 xxxxxxxx-xxxx-xxxx-xxxxxxxx 的唯一ID export function uuid(pipe = '-') { - var str = crypto.randomUUID() - var now = (~~(Date.now() / 1000)).toString(16) + let str = crypto.randomUUID() + let now = (~~(Date.now() / 1000)).toString(16) if (__inc__ > 65535) { __inc__ = 4096 @@ -121,11 +121,12 @@ export function md5(str, encode) { * @param {Str} file [文件路径] */ export function md5Sign(file) { - if (fs.accessSync(file, fs.constants.R_OK)) { - var buf = fs.readFileSync(file) + try { + let buf = fs.readFileSync(file) return hash('md5', buf) + } catch (e) { + return null } - return null } /** @@ -149,11 +150,12 @@ export function sha1(str, encode) { * @param {Str} file [文件路径] */ export function sha1Sign(file) { - if (fs.accessSync(file, fs.constants.R_OK)) { - var buf = fs.readFileSync(file) + try { + let buf = fs.readFileSync(file) return hash('sha1', buf) + } catch (e) { + return null } - return null } /** @@ -177,11 +179,12 @@ export function sha256(str, encoding) { * @param {Str} file [文件路径] */ export function sha256Sign(file) { - if (fs.accessSync(file, fs.constants.R_OK)) { - var buf = fs.readFileSync(file) + try { + let buf = fs.readFileSync(file) return hash('sha256', buf) + } catch (e) { + return null } - return null } export {