Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.put = async (key, contents) => {
const service = new azStorage.BlobService(storageAccount.name.get());
const readableStream = new ReadableStream(contents);
await new Promise((resolve, reject) => {
service.createBlockBlobFromStream(container.name.get(), key, readableStream, contents.length, err => {
if (err) {
return reject(err);
}
resolve();
});
});
};
this.delete = async (key) => {
const service = new azStorage.BlobService(storageAccount.name.get());
await new Promise((resolve, reject) => {
service.deleteBlob(container.name.get(), key, (err: Error) => {
if (err) {
return reject(err);
}
resolve();
});
});
};
private getBlobService(urlObject: Url.Url): AzureStorage.BlobService {
const blobEndpoint = Url.format({
protocol: urlObject.protocol,
host: urlObject.host
});
const sharedAccessSignature = urlObject.query as string;
const connectionString = "BlobEndpoint=" + blobEndpoint + ";" + "SharedAccessSignature=" + sharedAccessSignature;
return new AzureStorage.BlobService(connectionString);
}
this.get = async (key) => {
const writableStream = new streamBuffers.WritableStreamBuffer();
const service = new azStorage.BlobService(storageAccount.name.get());
await new Promise((resolve, reject) => {
service.getBlobToStream(container.name.get(), key, writableStream, err => {
if (err) {
return reject(err);
}
resolve();
});
});
return writableStream.getContents() || Buffer.from([]);
};