node.js - 如何从节点中的文件缓冲区创建十六进制
问题描述
使用 Typescript / Node / Crypto 创建哈希。
const fileBuffer = readFileSync(filePath);
const hashedFileName = crypto
.createHash("md5")
.update(fileBuffer)
.digest("hex");
但是得到一个...
Argument of type 'ArrayBuffer' is not assignable to parameter of type 'BinaryLike'.
Type 'ArrayBuffer' is missing the following properties from type 'Float64Array': BYTES_PER_ELEMENT, buffer, byteOffset, copyWithin, and 23 more.
有没有办法使这项工作?什么是 BinaryLike?
解决方案
AnArrayBuffer
不是有效参数,因为.update
您必须将其转换为Buffer
orUint8Array
const hashedFileName = crypto
.createHash("md5")
.update(Uint8Array.from(fileBuffer))
.digest("hex");
推荐阅读
- javascript - jquery获取元素值,然后设置到图表js中
- javascript - 画布和鼠标位置不对齐
- makefile - Android.mk 中的 LOCAL_HEADER_LIBRARIES 是什么?
- mysql - 无法删除IN子句mysql中的所有记录
- css - 在 bootstrap 4 自定义中导入哪些部分
- java - 快速排序分区调整
- twitter-bootstrap - Bootstrap 5中带有多个单选组的个人选择
- python - Python - pyplot - 查看 x 轴的所有值
- c - fgets() 和初始化变量的奇怪程序行为
- android - Android Studio Emulator (Nexus 4 API 26) - 无法使用网络摄像头拍照