| 31 | * ``` |
| 32 | */ |
| 33 | export default class FolderAdapter extends BaseFileSystem implements FileSystem { |
| 34 | public static readonly Name = "FolderAdapter"; |
| 35 | |
| 36 | public static readonly Options: FileSystemOptions = { |
| 37 | folder: { |
| 38 | type: "string", |
| 39 | description: "The folder to use as the root directory" |
| 40 | }, |
| 41 | wrapped: { |
| 42 | type: "object", |
| 43 | description: "The file system to wrap" |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * Creates a FolderAdapter instance with the given options. |
| 49 | */ |
| 50 | public static Create(opts: FolderAdapterOptions, cb: BFSCallback<FolderAdapter>): void { |
| 51 | cb(null, new FolderAdapter(opts.folder, opts.wrapped)); |
| 52 | } |
| 53 | public static isAvailable(): boolean { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | public _wrapped: FileSystem; |
| 58 | public _folder: string; |
| 59 | /** |
| 60 | * Wraps a file system, and uses the given folder as its root. |
| 61 | * |
| 62 | * @param folder The folder to use as the root directory. |
| 63 | * @param wrapped The file system to wrap. |
| 64 | */ |
| 65 | constructor(folder: string, wrapped: FileSystem) { |
| 66 | super(); |
| 67 | this._folder = folder; |
| 68 | this._wrapped = wrapped; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Initialize the file system. Ensures that the wrapped file system |
| 73 | * has the given folder. |
| 74 | */ |
| 75 | public initialize(cb: (e?: ApiError) => void) { |
| 76 | this._wrapped.exists(this._folder, (exists: boolean) => { |
| 77 | if (exists) { |
| 78 | cb(); |
| 79 | } else if (this._wrapped.isReadOnly()) { |
| 80 | cb(ApiError.ENOENT(this._folder)); |
| 81 | } else { |
| 82 | this._wrapped.mkdir(this._folder, 0x1ff, cb); |
| 83 | } |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | public getName(): string { return this._wrapped.getName(); } |
| 88 | public isReadOnly(): boolean { return this._wrapped.isReadOnly(); } |
| 89 | public supportsProps(): boolean { return this._wrapped.supportsProps(); } |
| 90 | public supportsSynch(): boolean { return this._wrapped.supportsSynch(); } |
nothing calls this directly
no outgoing calls
no test coverage detected