Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
az-blob-readstream
Advanced tools
Zero dependency wrapper to stream files from an Azure Blob Storage container
Azure Blob Storage Read Stream made easy
Simple wrapper around Azure BlobClient downloadToBuffer
method allowing intuitive and stable streaming.
To install the package:
npm install az-blob-readstream
You can integrate the BlobReadstream
class with the @azure/storage-blob
package easily:
import { BlobServiceClient } from "@azure/storage-blob";
import { BlobReadstream } from "az-blob-readstream";
const CONNECTION_STRING = "<your blob storage connection string>";
// Setup the connection to blob storage, the container, and the blob
const serviceClient = BlobServiceClient.fromConnectionString(CONNECTION_STRING);
const containerClient = serviceClient.getContainerClient("<container name>");
const blobClient = containerClient.getBlobClient("<blob name>");
// Get metadata properties so we know the size of the file
const metadata = await blobClient.getProperties();
// Create BlobReadstream object instead of calling the blob clients download method.
const parameters = {
blobClient, // Pass in the blobClient
contentLength: metadata.contentLength, // The length of the file being read
byteRange: 1024 * 1024 // Amount of bytes in each chunk (optional - defaults to 64 KiB)
}
const stream = new BlobReadstream(parameters);
BlobDownloadToBufferOptions
The downloadToBufferOptions
parameter allows you to pass in any BlobDownloadToBufferOptions
to the Azure Blob Storage downloadToBuffer
method.
const parameters = {
blobClient,
contentLength,
byteRange,
downloadToBufferOptions: {
maxRetryRequestPerBlock: 10
}
};
const stream = new BlobReadstream(parameters);
Just like in the @azure/storage-blob
sdk, omitting this perameter will default all values in BlobDownloadToBufferOptions
.
To adjust the range of bytes grabbed from Azure Blob Storage:
// You can adjust the range at any point during the stream (adjusting the speed)
stream.adjustByteRange(1024 * 1024 * 5); // 5 MiB
To adjust cursor position:
// You can move the cursor forwards to skip ahead (or back) in the file
// By default, the stream will skip ahead by the current Range
stream.moveCursorForward();
stream.moveCursorBack();
// Both of these methods also take in a `bytes` parameter for finer control
stream.moveCursorForward(10 * 1024); // Move cursor forward 10 KiB in file
stream.moveCursorBack(5 * 1024); // Move cursor back 5 KiB in file
You can alse use this BlobReadstream
like any other NodeJS Readable stream, setting an event listener is exactly the same:
stream.on('data', (chunk) => {
console.log(`read: ${chunk.toString()}`);
});
stream.on('end', () => {
console.log('end');
});
To work with zipped files:
import { createGunzip } from 'zlib';
const gzip = createGunzip();
// pipe into gzip to unzip files as you stream!
stream.pipe(gzip);
BlobReadstream(parameters: BlobReadstreamParameters)
Instantiates a new BlobReadstream
object.
Parameters:
parameters
(BlobReadstreamParameters) - Container object to hold parameters
parameters.blobClient
(BlobClient) - Azure Blob Storage Blob Clientparameters.contantLength
(number) - Size of file to downloadparameters.byteRange
(number) - (optional) Range of bytes to grab in each downloadToBuffer
call (defaults to 64 KiB)parameters.downloadToBufferOptions
(BlobDownloadToBufferOptions) - (optional) Options to pass to downloadToBuffer
callnodeReadableStreamOptions
(ReadableOptions) - (optional) NodeJs Readable options to pass to super calladjustByteRange(bytes: number)
Adjusts the BlobReadstream.range
property. Can be used to slow down or speed up the stream by grabbing a smaller or larger range of bytes.
Parameter:
bytes
(number) - New range of bytes to setmoveCursorForward(bytes: number)
Drains the internal buffer and adjusts the BlobReadstream.curr
property moving the cursor forward bytes
amount.
If current cursor position + number of bytes to move forward is > the length of the file, set cursor at end of file
Parameter:
bytes
(number) - (optional) Number of bytes to move forward (defaults to current range)moveCursorBack(bytes: number)
Drains the internal buffer and adjusts the BlobReadstream.curr
property moving the cursor back bytes
amount.
If current cursor position - number of bytes to move back is <= 0, set cursor at begining of file
Parameter:
bytes
(number) - (optional) Number of bytes to move forward (defaults to current range)FAQs
Zero dependency wrapper to stream files from an Azure Blob Storage container
We found that az-blob-readstream demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.