@atomist/automation-client
Version:
Atomist API for software low-level client
53 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractFile_1 = require("../support/AbstractFile");
/**
* In memory File implementation. Useful in testing
* and to back quasi-synchronous operations. Do not use
* for very large files.
*/
class InMemoryFile extends AbstractFile_1.AbstractFile {
constructor(path, content) {
super();
this.path = path;
this.content = content;
this.initialPath = path;
this.initialContent = content;
}
getContentSync(encoding) {
return this.content;
}
setContentSync(content) {
this.content = content;
this.invalidateCache();
return this;
}
setContent(content) {
return Promise.resolve(this.setContentSync(content));
}
getContent(encoding) {
return Promise.resolve(this.getContentSync(encoding));
}
getContentBuffer() {
return Promise.resolve(Buffer.from(this.getContentSync(), "utf8"));
}
setPath(path) {
this.path = path;
return Promise.resolve(this);
}
get dirty() {
return this.initialContent !== this.getContentSync() || this.initialPath !== this.path || super.dirty;
}
isExecutable() {
throw new Error("isExecutable is not implemented here");
}
isReadable() {
throw new Error("isReadable is not implemented here");
}
isBinary() {
// InMemoryFile does not presently support binary files
return Promise.resolve(false);
}
}
exports.InMemoryFile = InMemoryFile;
//# sourceMappingURL=InMemoryFile.js.map