@akadenia/azure-storage
Version:
Microsoft Azure storage helper methods
118 lines (117 loc) • 5.96 kB
TypeScript
import { BlobHTTPHeaders, BlobItem, BlobServiceClient, HttpRequestBody } from "@azure/storage-blob";
import { Readable } from "stream";
export declare enum BlobPermissions {
READ = "r",
WRITE = "w",
CREATE = "c",
DELETE = "d",
ADD = "a"
}
export interface SASOptions {
startsOn?: Date;
expiresOn?: Date;
permissions?: BlobPermissions[];
}
interface SASUrlComponents {
sasQueryString: string;
containerName: string;
blobName?: string;
fullUrl: string;
fullUrlWithSAS: string;
}
/**
* @class BlobStorage - A class that contains azure blob storage helpers
*/
export declare class BlobStorage {
private connectionStringOrSASUrl;
constructor(connectionStringOrSASUrl: string);
isEmulatorConnection(): boolean;
isSASUrl(): boolean;
/**
* @returns {BlobServiceClient} - A BlobServiceClient object
*/
getBlobServiceUrl(): BlobServiceClient;
/**
* Creates a container in Azure Blob Storage if it does not already exist.
*
* @param containerName - The name of the container to create.
* @param sasUrl - Optional. The SAS URL for accessing the Blob service. If not provided, the default Blob service URL will be used.
* @returns A promise that resolves to a boolean indicating whether the container was successfully created or already exists.
*/
createContainer(containerName: string): Promise<boolean>;
/**
* Deletes a container in Azure Blob Storage if it exists.
*
* @param containerName - The name of the container to delete.
* @returns A promise that resolves to a boolean indicating whether the container was successfully deleted.
*/
deleteContainer(containerName: string): Promise<boolean>;
/**
* @param {string} containerName - The name of the container to check
* @param {string} blobNamePrefix - The prefix of the blob name
* @returns {Promise<Array<BlobItem>>} - An array of BlobItem objects
*/
listBlobs(containerName: string, blobNamePrefix: string): Promise<BlobItem[]>;
/**
* @param {string} containerName - The name of the container to download from
* @param {string} blobName - The name of the blob to download
* @returns {Promise<Buffer>} - A Buffer object
*/
downloadBlob(containerName: string, blobName: string): Promise<Buffer>;
/**
* @param {string} containerName - The name of the container to check
* @param {string} blobName - The name of the blob to check
* @returns {Promise<boolean>} - A boolean indicating whether or not the blob exists
*/
blobExists(containerName: string, blobName: string): Promise<boolean>;
/**
* @param {string} containerName - The name of the container to upload to
* @param {string} blobName - The name of the blob to upload
* @param {HttpRequestBody} body - The body of the blob
* @param {string} contentLength - The content length
* @param {string} contentType - The content type of the blob
* @returns {Promise<boolean>} - A boolean indicating whether or not the blob was successfully uploaded
*/
upload(containerName: string, blobName: string, body: HttpRequestBody, contentLength: number, contentType: string): Promise<boolean>;
/**
* @param {string} containerName - The name of the container to upload to
* @param {string} blobName - The name of the blob to upload
* @param data - Buffer | Blob | ArrayBuffer | ArrayBufferView
* @param {BlobHTTPHeaders} [blobHTTPHeaders] - The blob HTTP headers to set while uploading the blob
* @param bufferSize - Size of every buffer allocated, also the block size in the uploaded block blob. Default value is 8MB
* @returns {Promise<boolean>} - A boolean indicating whether or not the blob was successfully uploaded
*/
uploadData(containerName: string, blobName: string, data: Buffer | Blob | ArrayBuffer | ArrayBufferView, blobHTTPHeaders?: BlobHTTPHeaders): Promise<boolean>;
/**
* @param {string} containerName - The name of the container to upload to
* @param {string} blobName - The name of the blob to upload
* @param stream - Node.js Readable stream
* @param {BlobHTTPHeaders} [blobHTTPHeaders] - The blob HTTP headers to set while uploading the blob
* @param bufferSize - Size of every buffer allocated, also the block size in the uploaded block blob. Default value is 8MB
* @returns {Promise<boolean>} - A boolean indicating whether or not the blob was successfully uploaded
*/
uploadStream(containerName: string, blobName: string, stream: Readable, blobHTTPHeaders?: BlobHTTPHeaders): Promise<boolean>;
/**
* * Generates a Shared Access Signature (SAS) URL for a blob or container
*
* @param {string} containerName - The name of the blob container
* @param {string} [blobName] - Optional. The name of the specific blob. If not provided, the SAS token will be generated for the container level
* @param {SASOptions} [sasOptions={}] - Optional. The options used for generating the SAS token
* @returns {SASUrlComponents} - Object containing:
* - fullUrlWithSAS: The complete URL with SAS token
* - fullUrl: The complete URL without SAS token
* - containerName: The name of the blob container
* - blobName: The name of the specific blob (if provided)
* - sasQueryString: The SAS token query parameters
*/
generateSASUrl(containerName: string, blobName?: string, sasOptions?: SASOptions): SASUrlComponents;
/**
* Deletes a blob from the specified container.
*
* @param {string} containerName - The name of the container containing the blob
* @param {string} blobName - The name of the blob to delete
* @returns {Promise<boolean>} - A boolean indicating whether the blob was successfully deleted
*/
deleteBlob(containerName: string, blobName: string): Promise<boolean>;
}
export {};