import { Readable , Writable } from 'stream' ; import { ListResult } from './Files' ; export const PathAbs = ( index = 0 ) => ( _ , __ , propDesc ) => { let originalFunction = propDesc . value ; propDesc . value = function ( ) { let argValue = arguments [ index ] ; let newArgs = [ ] ; for ( let i = 0 ; i < arguments . length ; i ++ ) newArgs . push ( arguments [ i ] ) ; newArgs [ index ] = ( this as any ) . pathAbs ( argValue ) ; return originalFunction . apply ( this , newArgs ) ; } ; return propDesc ; } ; export interface StorageOptions { directory ? : string ; } export abstract class Storage < O extends StorageOptions = any > { public readonly options : O ; public directoryNormalized : string ; constructor ( options ) { this . options = options ; const directory = this . options . directory || '' ; this . directoryNormalized = directory . charAt ( 0 ) === '/' ? directory . substring ( 1 ) : directory ; } abstract getTopLevel ( path ? ) ; abstract getFilesStream ( path ? ) ; abstract readFile ( filePath ) ; abstract writeFile ( filePath , data ) ; abstract deleteFile ( filePath ) ; abstract getFileSize ( filePath ) ; abstract createWriteStream ( filePath ) ; abstract createReadStream ( filePath ) ; abstract makeDir ( path ) ; public pathAbs ( path ) { const pathNormalized = path . charAt ( 0 ) === '/' ? path . substring ( 1 ) : path ; return this . directoryNormalized . length > 0 ? `${ this . directoryNormalized }/${ pathNormalized }` : pathNormalized ; } }