UNPKG

1.45 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const AbstractFile_1 = require("../support/AbstractFile");
4/**
5 * In memory File implementation. Useful in testing
6 * and to back quasi-synchronous operations. Do not use
7 * for very large files.
8 */
9class InMemoryFile extends AbstractFile_1.AbstractFile {
10 constructor(path, content) {
11 super();
12 this.path = path;
13 this.content = content;
14 this.initialPath = path;
15 this.initialContent = content;
16 }
17 getContentSync() {
18 return this.content;
19 }
20 setContentSync(content) {
21 this.content = content;
22 return this;
23 }
24 setContent(content) {
25 return Promise.resolve(this.setContentSync(content));
26 }
27 getContent() {
28 return Promise.resolve(this.getContentSync());
29 }
30 setPath(path) {
31 this.path = path;
32 return Promise.resolve(this);
33 }
34 get dirty() {
35 return this.initialContent !== this.getContentSync() || this.initialPath !== this.path || super.dirty;
36 }
37 isExecutable() {
38 throw new Error("isExecutable is not implemented here");
39 }
40 isReadable() {
41 throw new Error("isReadable is not implemented here");
42 }
43 isBinary() {
44 // InMemoryFile does not presently support binary files
45 return Promise.resolve(false);
46 }
47}
48exports.InMemoryFile = InMemoryFile;
49//# sourceMappingURL=InMemoryFile.js.map
\No newline at end of file