使用pipeThrough/pipeTo进行转换然后流式传输到Azure Blob

问题描述 投票:0回答:1

我正在尝试从 API 流式传输一些数据,对其进行转换,然后使用 Azure 函数上传到 Azure blob。我使用 Azure Blobstore 面临的限制是没有“writeStream”,只有 uploadStream。管道中没有明显的点可以上传到流。

示例-

   function MyWriter(writer) {
      return new WritableStream({
        write(chunk) {
          console.log('writing');
          writer.write(chunk);
        },
      });
    }

    export const generate = async (iterable) => { 
      await ReadableStream.from(iterable);
        .pipeThrough(new TextDecoderStream())
        .pipeThrough(new MyTransformer())
        .pipeThrough(new CompressionStream('gzip'))
        .pipeTo(MyWriter(writeOutStream));

    /*. await blockBlobClient.uploadStream(); */
    }

我错过了一些明显的东西吗?

Azure 上传流文档 - https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-upload-javascript#upload-a-block-blob-from-a-stream

尝试了各种管道组合,但没有明显的上传流的点。

javascript node.js azure-blob-storage streaming
1个回答
0
投票
  const readableStream = ReadableStream.from(myIterable);
        .pipeThrough(new TextDecoderStream())
        .pipeThrough(new MyTransformer())
        .pipeThrough(new CompressionStream('gzip'));

  await blockBlobClient.uploadStream(Readable.fromWeb(readableStream), readableStream);
    'blobbyBlobbyBlobby.xml.gz',
  );
© www.soinside.com 2019 - 2024. All rights reserved.