@comunica/actor-rdf-resolve-quad-pattern-hdt
Version:
A hdt rdf-resolve-quad-pattern actor
40 lines • 1.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HdtIterator = void 0;
const asynciterator_1 = require("asynciterator");
class HdtIterator extends asynciterator_1.BufferedIterator {
constructor(hdtDocument, subject, predicate, object, options) {
super(options || { autoStart: false });
this.hdtDocument = hdtDocument;
this.subject = subject;
this.predicate = predicate;
this.object = object;
this.position = options && options.offset || 0;
this.hdtDocument.countTriples(this.subject, this.predicate, this.object)
.then((searchResult) => {
this.setProperty('metadata', { totalItems: searchResult.totalCount });
})
.catch(error => this.destroy(error));
}
_read(count, done) {
if (this.hdtDocument.closed) {
this.close();
return done();
}
this.hdtDocument.searchTriples(this.subject, this.predicate, this.object, { offset: this.position, limit: count })
.then((searchResult) => {
searchResult.triples.forEach(t => this._push(t));
if (searchResult.triples.length < count) {
this.close();
}
done();
})
.catch(error => {
this.emit('error', error);
return done();
});
this.position += count;
}
}
exports.HdtIterator = HdtIterator;
//# sourceMappingURL=HdtIterator.js.map