semantic-analysis
Version:
Extensible semantic Structured Data analysis library for Microdata and JSON-LD
48 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VisitLogFile = void 0;
var tslib_1 = require("tslib");
var fs = tslib_1.__importStar(require("fs"));
var readline = tslib_1.__importStar(require("readline"));
var VisitLog_1 = require("./VisitLog");
/**
* Logs visited URLs to prevent repeated scans
* with file backing up solution
*/
var VisitLogFile = /** @class */ (function (_super) {
tslib_1.__extends(VisitLogFile, _super);
/* Initialization */
function VisitLogFile(path) {
var _this = _super.call(this) || this;
_this.path = path;
_this.setupFromFile = function (path) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _this = this;
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve) {
var rlPath = path !== null && path !== void 0 ? path : _this.path;
if (rlPath && fs.existsSync(rlPath) && fs.lstatSync(rlPath).isFile()) {
var readIf = readline.createInterface({ input: fs.createReadStream(rlPath) });
readIf.on('line', function (line) { return _this.add(line); });
readIf.on('close', function () { return resolve(true); });
}
else {
resolve(false);
}
})];
});
}); };
return _this;
}
/* Manipulation */
VisitLogFile.prototype.add = function (url) {
var _a;
_super.prototype.add.call(this, url);
if (!this.logger && this.path) {
this.logger = fs.createWriteStream(this.path, { flags: 'a' });
}
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.write(url + '\n');
};
return VisitLogFile;
}(VisitLog_1.VisitLog));
exports.VisitLogFile = VisitLogFile;
//# sourceMappingURL=VisitLogFile.js.map