0

有没有从谷歌存储桶读取二进制文件的最佳方法,我正在尝试下面的代码,但是当我尝试从存储桶中读取文件并提取时,我面临非法偏移问题。

我已经在 fabriccerts 存储桶下手动上传了扩展名为 .tx 的二进制文件。我必须读取云函数中的文件并使用 fabrclient 模块提取相同的文件。

下面是从桶中读取文件的函数。

 const {Storage} = require('@google-cloud/storage');
    const storage = new Storage();
    async function getFileContent(fileName, bucketName) {
      const myBucket = storage.bucket(bucketName);
      const file = myBucket.file(fileName);
      const content = await file.download();
      return content;
    };

下面是来自云函数的语句,我试图使用 fabric-client 模块提取二进制文件。

const Client = require('fabric-client');
    let envelope_bytes = await storage_util.getFileContent("channel.tx", "fabriccerts");
   console.log("file data" + envelope_bytes);
    let config_update = client.extractChannelConfig(envelope_bytes);
Error: Error: function terminated. Recommended action: inspect logs for termination reason. Details:
Illegal offset: 0 <= 1 (+1) <= 1

有没有特定的方法来读取二进制文件?下载后需要转换文件吗?

我在 ubuntu 机器上尝试了相同的操作,将 channel.tx 文件存储在本地目录中,该目录工作正常,并在读取文件后显示如下:

    �
                                                                                                                                                               ����"     mychannel�
    �
            mychannel;)

    Application

    Org1MSP

    Org2MSP

    Consortium��

    Application�

    Org2MSP

    Org1MSP&
    Capabilities



    V1_4_2Admins""
    WritersAdmins""
    Admins

    AdminsAdmins""
    ReadersAdmins*Admins"

    Consortium
    SampleConsortium

但是当我将相同的文件存储在存储桶中并读取它显示以下数据的文件时:

    �  ����" mychannel� � mychannel;) Application Org1MSP� Org2MSP� Consortium��� Application� Org2MSP� Org1MSP�&amp; Capabilities V1_4_2�Admins"" Writers  WritersAdmins"" Admins AdminsAdmins"" Readers  ReadersAdmins*Admins" Consortium SampleConsortium

错误日志:

RangeError: Illegal offset: 0 <= 1 (+1) <= 1 at ByteBuffer.module.exports.ByteBufferPrototype.readVarint32 (/srv/node_modules/bytebuffer/dist/bytebuffer-node.js:1540:23) at Message.ProtoBuf.Reflect.MessagePrototype.decode (/srv/node_modules/fabric-client/node_modules/protobufjs/dist/protobuf.js:3237:36) at Function.Message.decode (/srv/node_modules/fabric-client/node_modules/protobufjs/dist/protobuf.js:2952:37) at Client.extractChannelConfig (/srv/node_modules/fabric-client/lib/Client.js:660:42) at Object.exports.createChannel (/srv/chainmanagement/channel-management.js:36:30) at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:229:7)

我们需要向 google 提出错误吗?

4

0 回答 0