最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何从节点中的文件缓冲区创建十六进制

网站源码admin18浏览0评论

如何从节点中的文件缓冲区创建十六进制

如何从节点中的文件缓冲区创建十六进制

使用打字稿/节点/加密来创建哈希。

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?

回答如下:

ArrayBuffer不是.update的有效参数,您必须将其转换为BufferUint8Array

const hashedFileName = crypto
      .createHash("md5")
      .update(Uint8Array.from(fileBuffer))
      .digest("hex");
发布评论

评论列表(0)

  1. 暂无评论