summaryrefslogtreecommitdiff
path: root/src/sources/FileSource.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/sources/FileSource.ts')
-rw-r--r--src/sources/FileSource.ts27
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);
+ });
+ });
+ }
+}