Skip to content

Commit

Permalink
fix auzure storage return buffer instead of stream
Browse files Browse the repository at this point in the history
  • Loading branch information
pofider committed Apr 11, 2023
1 parent 7d90594 commit 9680758
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/jsreport-azure-storage/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const stream = require('stream')
const { BlobServiceClient, StorageSharedKeyCredential } = require('@azure/storage-blob')
const { DefaultAzureCredential } = require('@azure/identity')

async function streamToBuffer (readable) {
const bufs = []
for await (const chunk of readable) {
bufs.push(chunk)
}
return Buffer.concat(bufs)
}

module.exports = function (reporter, definition) {
if (reporter.options.blobStorage.provider !== 'azure-storage') {
definition.options.enabled = false
Expand Down Expand Up @@ -34,15 +41,8 @@ module.exports = function (reporter, definition) {
reporter.blobStorage.registerProvider({
init: () => containerClient.createIfNotExists(),
read: async (blobName) => {
try {
const res = await containerClient.getBlockBlobClient(blobName).download()
return res.readableStreamBody
} catch (e) {
const r = stream.Readable()
r._read = () => {}
process.nextTick(() => r.emit('error', e))
return r
}
const res = await containerClient.getBlockBlobClient(blobName).download()
return streamToBuffer(res.readableStreamBody)
},
write: async (blobName, buffer) => {
await containerClient.getBlockBlobClient(blobName).upload(buffer, Buffer.byteLength(buffer))
Expand Down

0 comments on commit 9680758

Please sign in to comment.