const fs = require('fs') const getFileBuffer = (path) => fs.readFileSync(path) const getFilePath = (prefixStr = '', postfixStr = '') => { // 文件名称 const uuid = () => { function s4 () { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1) } return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4() } // 文件扩展名 toLowerCase 转小写 let prefix = prefixStr if (prefixStr && prefix.substr(prefix.length - 1, 1) !== '/') { prefix += '/' } // 后缀 let postfix = '' if (postfixStr) { postfix = '_' + postfixStr } return prefix + uuid() + postfix + '.jpg' } const uuid = () => { function s4 () { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1) } return s4() + s4() + s4() } module.exports = { getFileBuffer, getFilePath, uuid }