Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function fillBuffer() { self._fillBuffer(); }
function emitError(error) { self.emit('error', error); }
// Add all readable sources and listen to their events
for (var i = 0, l = sources.length; i < l; i++) {
var source = sources[i];
if (source && !source.ended) {
this._sources.push(source);
source.on('readable', fillBuffer);
source.on('end', fillBuffer);
source.on('error', emitError);
}
}
}
}
BufferedIterator.subclass(UnionIterator);
// Reads items from the sources in a round-robin way
UnionIterator.prototype._read = function (count, done) {
var sources = this._sources, item = null, attempts = sources.length;
// While no item has been found, attempt to read all sources once
while (item === null && attempts--) {
var source = sources[this._sourceIndex];
item = source.read();
// Remove the current source if it has ended
if (source.ended)
sources.splice(this._sourceIndex, 1);
// Otherwise, start from the succeeding source next time
else
this._sourceIndex++;
if (this._sourceIndex >= sources.length)
this._sourceIndex = 0;
// Process a fragment error
fragment.once('error', function (error) {
// Only error if the threshold across fragments has been reached
if (errorThreshold-- === 0)
return compoundFragment.emit('error', error);
// Otherwise, silently assume this fragment has no results
processMetadata({});
fragmentDone();
});
});
// Make the compound fragment become readable
function setReadable() { compoundFragment.readable = true; }
}
BufferedIterator.subclass(CompoundFragment);
// Reads elements of the first non-empty child fragments
CompoundFragment.prototype._read = function (count, done) {
var fragments = this._fragments;
for (var index in fragments) {
var fragment = fragments[index], item;
// Try to read as much items from the fragment as possible
while (count > 0 && (item = fragment.read()))
this._push(item), count--;
// Stop if we have read sufficient elements
if (!count) break;
}
done();
};
// Empties the fragment
/** Aborts all requests. */
FragmentsClient.prototype.abortAll = function () {
this._httpClient.abortAll();
};
// Creates a new Triple Pattern Fragment
function Fragment(fragmentsClient, pattern) {
if (!(this instanceof Fragment))
return new Fragment(fragmentsClient);
BufferedIterator.call(this);
this._fragmentsClient = fragmentsClient;
this._pattern = pattern;
}
BufferedIterator.subclass(Fragment);
// Reads data from the current page of the fragment
Fragment.prototype._read = function (count, done) {
var item;
while (count-- > 0 && this._page && (item = this._page.read()))
this._push(item);
done();
};
// Loads the Triple Pattern Fragment located at the given URL
Fragment.prototype.loadFromUrl = function (pageUrl) {
// Fetch a page of the fragment
var fragment = this, fragmentsClient = this._fragmentsClient, rawPage,
headers = { 'user-agent': 'Triple Pattern Fragments Client' };
if (fragmentsClient._startFragmentUrl) headers.referer = fragmentsClient._startFragmentUrl;
rawPage = fragmentsClient._httpClient.get(pageUrl, headers);