'use strict' ; import { Stream } from 'stream' ; import { StreamToBuffer , StreamToString } from './StreamUtils' ; /** Dictionary of objects returned when listing a container. */ export interface ListItemObject { /** Full path of the object inside the container */ path : string ; /** Size in bytes of the object */ size : number ; /** Date when the object was last modified */ lastModified : Date ; /** Date when the object was created */ creationTime ? : Date ; /** Content-Type header of the object, if present */ contentType ? : string ; /** MD5 digest of the object, if present */ contentMD5 ? : string ; /** SHA1 digest of the objet, if present */ contentSHA1 ? : string ; } /** Dictionary of options used when putting an object. Many providers will extend this. */ export interface PutObjectOptions { /** Key-value pair with metadata for the object, for example `Content-Type`, or custom tags */ metadata ? : any ; } /** Dictionary of prefixes returned when listing a container. */ export interface ListItemPrefix { /** Name of the prefix */ prefix : string ; } /** The `listObjects` method returns an array with a mix of objects of type `ListItemObject` and `ListItemPrefix` */ export interface ListResults { files : Array < ListItemObject > ; folders : Array < ListItemPrefix > ; } /**
 * Base class for all storage providers.
 */ export abstract class StorageProvider { protected _client : any ; protected _provider : string ; param connection protected constructor ( protected readonly connection ) { if ( ! connection || ! Object . keys ( connection ) . length ) { throw new Error ( 'Connection argument is empty' ) ; } this . _client = null ; this . _provider = null ; } returns get provider ( ) : string { return this . _provider ; } returns get client ( ) : any { return this . _client ; } param container param options returns async abstract createContainer ( container , options ? ) ; param container returns async abstract isContainer ( container ) ; param container param options returns async abstract ensureContainer ( container , options ? ) ; returns async abstract listContainers ( ) ; param container returns async abstract deleteContainer ( container ) ; param container param path param data param options returns async abstract putObject ( container , path , data , options ? ) ; param container param path returns async abstract getObject ( container , path ) ; abstract getObjectBase64 ( container , path ) ; param container param path returns async getObjectAsBuffer ( container , path ) { return this . getObject ( container , path ) . then ( ( stream ) => StreamToBuffer ( stream ) ) ; } param container param path param encoding returns async getObjectAsString ( container , path , encoding ? ) { return this . getObject ( container , path ) . then ( ( stream ) => StreamToString ( stream , encoding ) ) ; } param container param prefix returns async abstract listObjects ( container , prefix ? ) ; param container param path returns async abstract deleteObject ( container , path ) ; param container param path param ttl returns async abstract presignedGetUrl ( container , path , ttl ? ) ; param container param path param options param ttl returns async abstract presignedPutUrl ( container , path , options ? , ttl ? ) ; }