diff options
| author | Tim Schiewe <git@tforge.de> | 2018-04-30 19:18:46 +0200 |
|---|---|---|
| committer | Tim Schiewe <git@tforge.de> | 2018-04-30 19:18:46 +0200 |
| commit | ac85779f3b67ffc2953c17d0824be62b1f0acc86 (patch) | |
| tree | 5442df8297c3620ed72af7e3ece2a77ad58cce35 /src/sources/FileSource.ts | |
| parent | 93b466df50d94d4c15715f5eb4d88a0be7d61c11 (diff) | |
| download | splus-ac85779f3b67ffc2953c17d0824be62b1f0acc86.tar.gz splus-ac85779f3b67ffc2953c17d0824be62b1f0acc86.zip | |
Implement interface/config based infrastructure
Fixes #2
Diffstat (limited to 'src/sources/FileSource.ts')
| -rw-r--r-- | src/sources/FileSource.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/sources/FileSource.ts b/src/sources/FileSource.ts new file mode 100644 index 0000000..fd4f6f7 --- /dev/null +++ b/src/sources/FileSource.ts @@ -0,0 +1,27 @@ +import {readFile} from 'fs'; + +import {ISource} from './ISource'; + +export class FileSource implements ISource { + private _path: string; + private _data: string = null; + + constructor(path: string) { + this._path = path; + } + + getData(): Promise<string> { + if (this._data) { + return Promise.resolve(this._data); + } + + return new Promise<string>((resolve, reject) => { + readFile(this._path, (err, data) => { + if (err) return reject(err); + + this._data = data.toString(); + resolve(this._data); + }); + }); + } +} |
