stardog-union/stardog.js

db.add API docs are not correct; it can accept a stream as well as a string

colleeseum opened this issue · 2 comments

Loading file in memory to stream afterward is not efficient nor inline with Javascript mentality.

jmrog commented

Thanks for this issue. However, I don't think stardog.js should accept a filename, because I don't think it should be in the business of reading files from a user's system (it's an HTTP wrapper library), and also because it is not generally possible at present to read a file in the browser given just a filename (things are starting to change a bit there, but just barely, and not in all major browsers).

More importantly, stardog.js already can accept a stream as an argument to db.add, so you don't actually need to load whole files into memory in order to send them. For example, in Node.js, you can do something like this (this is pseudo-code-ish, but expresses the idea):

const rdfStream = fs.createReadStream(filePath);
db.add(conn, dbId, transactionId, rdfStream, options).then(/* . . . */);

Probably the real issue here is that our API docs for db.add claim that the content argument must be a string, and that is false. We should update the docs. I'll change the name of this issue to reflect that.

It the typescript type must be adjusted as well. as a work around you can use

// @ts-ignore

to workaround this issue. Thanks @jmrog