最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 11浏览 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");

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

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

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. 暂无评论