Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SparqlXMLResultWriter.prototype._writeHead = function (variableNames) {
// Write root element
var self = this,
root = this._root = xml.element({
_attr: { xlmns: 'http://www.w3.org/2005/sparql-results#' },
});
xml({ sparql: root }, { stream: true, indent: ' ', declaration: true })
.on('data', function (chunk) { self._push(chunk + '\n'); });
// Write head element
if (variableNames.length) {
root.push({
head: variableNames.map(function (v) {
return { variable: { _attr: { name: v } } };
}),
});
}
};
SparqlXMLResultWriter.prototype._flush = function (done) {
// If there were no matches, the results element hasn't been created yet
if (this._empty)
this._root.push({ results: this._results = xml.element({}) });
// There's no results element for ASK queries
if (this._results)
this._results.close();
this._root.close();
done();
};
test('streams end properly', t => {
const elem = xml.element({ _attr: { decade: '80s', locale: 'US'} });
const xmlStream = xml({ toys: elem }, { stream: true });
let gotData = false;
t.plan(7);
elem.push({ toy: 'Transformers' });
elem.push({ toy: 'GI Joe' });
elem.push({ toy: [{name: 'He-man'}] });
elem.close();
xmlStream.on('data', (data: any) => {
t.ok(data);
gotData = true;
});
test('streams end properly', t => {
const elem = xml.element({ _attr: { decade: '80s', locale: 'US'} });
const xmlStream = xml({ toys: elem }, { stream: true });
let gotData = false;
t.plan(7);
elem.push({ toy: 'Transformers' });
elem.push({ toy: 'GI Joe' });
elem.push({ toy: [{name: 'He-man'}] });
elem.close();
xmlStream.on('data', (data: any) => {
t.ok(data);
gotData = true;
});
file.on('open', function(fd) {
var indexRoot = xml.element({ _attr: {xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'}});
var xmlstream = xml({ sitemapindex: indexRoot}, { stream: true, indent: ' ', declaration: {encoding: 'UTF-8'}});
xmlstream.on('data', function (chunk) {
file.write(chunk + '\n');
if (chunk == endMarker) {
file.write('\n');
}
});
results.forEach(function(res) {
if (res.value.result) {
indexRoot.push({ sitemap: [{ loc: HOSTNAME + '/sitemap_' + res.value.origin.name + '.xml'}] });
} else {
console.log('An Error occured during the creation of the ' + res.value.origin.name + ' sitemap. ------> SKIPPED!');
}
});
this.normaliseLogStream = function(inputStream, pathEvalCallback) {
var logEntryScanner = new LogEntryScanner(_.partialRight(transformNodeChildren, pathEvalCallback));
var rootElement = xml.element();
var outputStream = xml({ log: rootElement }, { declaration: true });
var reader = XmlReader.create({ stream: true });
reader.on('tag:logentry', function(node) {
var logentryElement = logEntryScanner.scan(node);
if (logentryElement !== null) {
rootElement.push(logentryElement);
}
});
inputStream
.on('data', function(chunk) { reader.parse(decoder.write(chunk)); })
.on('end', function() { rootElement.close(); });
return outputStream;
};
};
constructor (source, variables, options) {
super(source, variables, options)
this._root = xml.element({
_attr: { xmlns: 'http://www.w3.org/2005/sparql-results#' }
})
this._results = xml.element({})
this._stream = xml({ sparql: this._root }, { stream: true, indent: '\t', declaration: true })
this._stream.on('data', v => this._push(v))
}
constructor (source, variables, options) {
super(source, variables, options)
this._root = xml.element({
_attr: { xmlns: 'http://www.w3.org/2005/sparql-results#' }
})
this._results = xml.element({})
this._stream = xml({ sparql: this._root }, { stream: true, indent: '\t', declaration: true })
this._stream.on('data', v => this._push(v))
}