[英]Hyperledger Fabric and NodeJS - How to convert buffer
I'm using Hyperledeger Fabric v1.1 and I'm developing a backend in NodeJs. 我正在使用Hyperledeger Fabric v1.1,并且正在NodeJ中开发后端。
Using the Fabric NodeJS SDK I can successfully query the blockchain and retrieve the information of the current block. 使用Fabric NodeJS SDK,我可以成功查询区块链并检索当前块的信息。
However, I can't properly convert the hash of the block from the Buffer type. 但是,我不能从Buffer类型正确转换块的哈希。
Below the snippet of the json that I retrieve from the blockchain. 从区块链中检索的json片段下方。
currentBlockHash:{
"buffer": {
"type": "Buffer",
"data": [8,38,18,32,150,172,137,248,232,203,159,23,44,4,75,29,169,171,120,165,83,22,158,45,93,3,37,120,100,164,229,211,49,194,208,181,26,32,119,47,159,196,237,190,29,24,139,56,212,190,59,126,77,80,76,228,28,171,108,134,241,97,162,190,84,39,240,25,115,135]
}
}
How can I convert this to a normal string in utf-8 in NodeJS? 如何在NodeJS的utf-8中将其转换为普通字符串?
您可以使用arraybuffer-to-string
npm package 。
var str = arrayBufferToString(buffer, encoding='utf8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.