Skip to content Skip to sidebar Skip to footer

Unable To Read Readablestreambody From Downloaded Blob

I can I check the internal buffer to see if my text data is present? Am I using node.js' Stream.read() correctly? I have a text file as a blob stored on azure-storage. When I downl

Solution 1:

According to your code, I see you were using Azure Storage SDK V10 for JavaScript.

In the npm page of this package @azure/storage-blob, there is an async function named streamToString in the sample code which can help you to read the content from readable stream, as below.

// A helper method used to read a Node.js readable stream into stringasyncfunctionstreamToString(readableStream) {
  returnnewPromise((resolve, reject) => {
    const chunks = [];
    readableStream.on("data", data => {
      chunks.push(data.toString());
    });
    readableStream.on("end", () => {
      resolve(chunks.join(""));
    });
    readableStream.on("error", reject);
  });
}

Then, your code will be writen like below.

asyncfunctiondownloadData(){
    const textfile = "name.txt"const containerURL = ContainerURL.fromServiceURL(serviceURL, "batches");
    const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, textfile );
    let baseLineImage = await blockBlobURL.download(aborter, 0);

    let content = awaitstreamToString(baseLineImage.readableStreamBody);
    console.log(content)
    return content
}

Hope it helps.

Post a Comment for "Unable To Read Readablestreambody From Downloaded Blob"