Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const terms = {
subject: subject ? rdfStore._exportTerm(subject) : null,
predicate: predicate ? rdfStore._exportTerm(predicate) : null,
object: object ? rdfStore._exportTerm(object) : null,
graph: graph ? rdfStore._exportTerm(graph) : null,
};
debug('terms: %j', terms);
const approximateCount = await rdfStore.getApproximateCount(terms);
let responseContentType;
try {
responseContentType = await ldfController._negotiate(res);
} catch (negotiationErr) {
res.status(400).end(negotiationErr.message);
return;
}
const writerStream = new n3.StreamWriter({
format: responseContentType
});
const quadStream = rdfStore.getStream(terms, { limit, offset });
const counterStream = createCounterStream();
quadStream.pipe(counterStream)
.pipe(writerStream, { end: false })
// .pipe(createDumperStream())
// .on('dump', (dump) => { console.log('DUMP', dump);})
.pipe(res);
await utils.resolveOnEvent(counterStream, 'finish', false);
const quadCount = counterStream.count;
const estimatedTotalCount = (quadCount && approximateCount < offset + quadCount)
? offset + (quadCount < limit ? quadCount : 2 * quadCount)
: approximateCount;
debug(`quadCount: ${quadCount}, approximateTotalCount: ${approximateCount}, estimatedTotalCount: ${estimatedTotalCount}`);
const thisUrl = new YURL(routeUrl).query(false).query(new YURL(`http://example.com/${req.originalUrl}`).parts.query).format();
function test_doc_from_triple_stream_to_rdf_stream() {
const streamParser: N3.N3StreamParser = new N3.StreamParser();
const inputStream = fs.createReadStream('cartoons.ttl');
const streamWriter: N3.N3StreamWriter = new N3.StreamWriter({ prefixes: { c: N3.DataFactory.namedNode('http://example.org/cartoons#') } });
inputStream.pipe(streamParser);
streamParser.pipe(streamWriter);
streamWriter.pipe(process.stdout);
}
public async runHandle(action: IActionRdfSerialize, mediaType: string, context: ActionContext)
: Promise {
const n3Triples = new Readable({ objectMode: true });
n3Triples._read = () => {
return;
};
action.quads.on('error', (e) => data.emit('error', e));
action.quads.on('data', (quad: RDF.Quad) => n3Triples.push(quad));
action.quads.on('end', () => n3Triples.emit('end'));
const data = n3Triples.pipe(new StreamWriter({ format: mediaType }));
return { data,
triples: mediaType === 'text/turtle'
|| mediaType === 'application/n-triples'
|| mediaType === 'text/n3' };
}
graphdb.searchStream = function(conditions, options) {
var stream;
if (options && options.n3) {
options.materialized = options.n3;
}
stream = db.searchStream(conditions, options);
if (options && options.n3) {
stream = stream.pipe(new n3.StreamWriter());
}
return stream;
};
return;
}
const terms = {
subject: subject ? rdfStore._exportTerm(subject) : null,
predicate: predicate ? rdfStore._exportTerm(predicate) : null,
object: object ? rdfStore._exportTerm(object) : null,
graph: graph ? rdfStore._exportTerm(graph) : null,
};
let responseContentType;
try {
responseContentType = await matchController._negotiate(res);
} catch (negotiationErr) {
res.status(400).end(negotiationErr.message);
return;
}
const writerStream = new n3.StreamWriter({
format: responseContentType,
prefixes: _.extend({}, prefixes)
});
const quadStream = rdfStore.getStream(terms, {limit, offset});
quadStream.pipe(writerStream).pipe(res);
});
}