Create HTTPFilesystem implementation and add support to universalPath helper to automatically use it
Some checks failed
continuous-integration/drone Build is failing
Some checks failed
continuous-integration/drone Build is failing
This commit is contained in:
42
src/util/support/path/ReadOnlyFilesystem.ts
Normal file
42
src/util/support/path/ReadOnlyFilesystem.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {ErrorWithContext} from '../../error/ErrorWithContext'
|
||||
import {Filesystem} from './Filesystem'
|
||||
import {Awaitable} from '../types'
|
||||
import {Writable} from 'stream'
|
||||
|
||||
/**
|
||||
* Error thrown when attempting to perform an operation on a filesystem that doesn't support it.
|
||||
*/
|
||||
export class FilesystemOperationNotSupported extends ErrorWithContext {
|
||||
constructor(fs: Filesystem, operation: string, context: any = {}) {
|
||||
super(`The filesystem ${fs.constructor.name} does not support the ${operation} operation.`, context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract base class for filesystems that are read-only (e.g. HTTP/S).
|
||||
*/
|
||||
export abstract class ReadOnlyFilesystem extends Filesystem {
|
||||
putLocalFile(): Awaitable<void> {
|
||||
throw new FilesystemOperationNotSupported(this, 'putLocalFile')
|
||||
}
|
||||
|
||||
putStoreFileAsStream(): Awaitable<Writable> {
|
||||
throw new FilesystemOperationNotSupported(this, 'putStoreFileAsStream')
|
||||
}
|
||||
|
||||
touch(): Awaitable<void> {
|
||||
throw new FilesystemOperationNotSupported(this, 'touch')
|
||||
}
|
||||
|
||||
remove(): Awaitable<void> {
|
||||
throw new FilesystemOperationNotSupported(this, 'remove')
|
||||
}
|
||||
|
||||
mkdir(): Awaitable<void> {
|
||||
throw new FilesystemOperationNotSupported(this, 'mkdir')
|
||||
}
|
||||
|
||||
setMetadata(): Awaitable<void> {
|
||||
throw new FilesystemOperationNotSupported(this, 'setMetadata')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user