UNPKG

@egodigital/egoose

Version:

Helper classes and functions for Node.js 10 or later.

145 lines (144 loc) 5.3 kB
/** * This file is part of the @egodigital/egoose distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/egoose is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/egoose is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /// <reference types="node" /> import * as azureStorage from 'azure-storage'; import { Readable } from 'stream'; /** * Options for an 'AzureStorageClient'. */ export interface AzureStorageClientOptions { /** * A custom function or string that provides the name of the underlying container. * If not defined, 'AZURE_STORAGE_CONTAINER' environment variable is used. * * @return {string|Function} The result with the container name or the container name as string. */ blobContainerProvider?: string | (() => string | Promise<string>); /** * A custom function, which detects a MIME type by a blob name / path, * * @param {string} path The blob path / name. * * @return {string|Promise<string>} The result with the detected MIME type. */ blobContentTypeDetector?: (path: string) => string | Promise<string>; /** * A custom function that provides the 'BlobService' instance to use. * If not defined, default settings from environment are used. * * @return {azureStorage.BlobService|Promise<azureStorage.BlobService>} The result with the service instance. */ blobServiceProvider?: () => azureStorage.BlobService | Promise<azureStorage.BlobService>; /** * A custom function that resolves a full blob path. * * @param {string} path The input path. * * @return {string|Promise<string>} The result with the full path. */ toFullBlobPath?: (path: string) => string | Promise<string>; /** * A custom function that creates a unique blob name. * * @param {string} path The input path / name of the blob. * * @return {string|Promise<string>} The result with a unique blob name / path. */ uniqueBlobNameCreator?: (path: string) => string | Promise<string>; } /** * An async Azure Storage client. */ export declare class AzureStorageClient { readonly options?: AzureStorageClientOptions; /** * Initializes a new instance of that class. * * @param {AzureStorageClientOptions} [options] The custom options. */ constructor(options?: AzureStorageClientOptions); /** * Creates a new blob service instance, based on the underlying options. * * @return {Promise<azureStorage.BlobService>} The promise with the new instance. */ createBlobService(): Promise<azureStorage.BlobService>; /** * Creates a read stream for a blob. * * @param {string} path The path of the blob. * * @return {Promise<Readable>} The promise with the stream. */ createBlobReadStream(path: string): Promise<Readable>; /** * Creates a new instance from environment settings. * * @return {AzureStorageClient} The new instance. */ static fromEnvironment(): AzureStorageClient; /** * Tries to return information about a blob. * * @param {string} path The path / name of the blob to check. * * @return {Promise<false|azureStorage.BlobService.BlobResult>} The promise that contains the blob information or (false) if it does not exist. */ getBlobInfo(path: string): Promise<false | azureStorage.BlobService.BlobResult>; private getContainer; /** * Lists a folder in a blob storage container. * * @param {string} path The path of the folder. * * @return {Promise<azureStorage.BlobService.BlobResult[]>} The promise with the result. */ listBlobs(path: string): Promise<azureStorage.BlobService.BlobResult[]>; /** * Loads a blob. * * @param {string} path The path / blob name. * * @return {Promise<Buffer>} The promises with the loaded data. */ loadBlob(path: string): Promise<Buffer>; /** * Saves / uploads a blob. * * @param {string} path The path / name of the blob. * @param {any} data The data to upload / store. */ saveBlob(path: string, data: any): Promise<void>; /** * Saves a blob with a unique name / path. * * @param {string} path The original path / name of the blob. * @param {any} data The data to store / save. * * @return {Promise<string>} The promise with the path / name of the stored blob. */ saveUniqueBlob(path: string, data: any): Promise<string>; private toFullPath; } /** * Normalizes an Azure blob path. * * @param {string} p The input path. * * @return {string} The normalized path. */ export declare function normalizeAzureBlobPath(p: string): string;