Skip to content

Commit

Permalink
feat(Azure Storage and helpers): getBinaryBlob and decompress gzip fi…
Browse files Browse the repository at this point in the history
…les functions (#147)

* feat(Azure Storage): getBinaryBlob and decompress gzip files functions

- This gets a binary blob  _without_ writing it to a file. This is a variation on the `getBlob` and `downloadBlobToFile` functions.
- New function to decompress gzip files

* chore: adds gunzip-maybe pacakge

* chore(deps-dev): bump globals in the dev-dependencies group (#146)



---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
beauraines and dependabot[bot] authored Oct 5, 2024
1 parent 2ef5020 commit ec156af
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 23 deletions.
221 changes: 212 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@azure/storage-queue": "^12.11.0",
"azure-devops-node-api": "^14.0.1",
"dayjs": "^1.11.7",
"gunzip-maybe": "^1.4.2",
"node-fetch": "^2.6.7",
"sparkly": "^5.0.0",
"sqlite": "^5.0.1",
Expand Down
27 changes: 25 additions & 2 deletions src/azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ getStorageQueueSignedURL(queueUrl,options) {

/**
* Gets a blob and returns the content. The idea is that you can get a blob without
* having to save it to a file and then re-read it. This may be limited in that it
* can only deal with non-binary content.
* having to save it to a file and then re-read it. This cannot handle binary data
*
* @param {string} containerName the container to get the blob from
* @param {string} blobName the name of the blob to get
Expand All @@ -236,6 +235,30 @@ getStorageQueueSignedURL(queueUrl,options) {

}


/**
* Gets a blob and returns the content as a Buffer.
*
* @param {string} containerName the container to get the blob from
* @param {string} blobName the name of the blob to get
* @returns {Buffer} the downloaded blob as
*/
async getBinaryBlob(containerName,blobName) {
const blobServiceClient = new BlobServiceClient(
this.host('blob',this.cloudName),
new StorageSharedKeyCredential(this.storageAccountName, this.storageAccountKey)
);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);

// Get blob content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody
const downloadBlockBlobResponse = await blobClient.download();
const downloaded = await streamToBuffer(downloadBlockBlobResponse.readableStreamBody);
return downloaded

}

/**
* Lists the blobs in a specified container, returning an array of the BlobItem object
*
Expand Down
Loading

0 comments on commit ec156af

Please sign in to comment.