Create HTTPFilesystem implementation and add support to universalPath helper to automatically use it
Some checks failed
continuous-integration/drone Build is failing

This commit is contained in:
2023-06-13 01:09:33 -05:00
parent 7c9b1ff212
commit 899c8448fc
7 changed files with 157 additions and 16 deletions

View 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')
}
}