This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Proposal for Standardising API that can return buffered results vs Node.js Streams vs Pull Streams #126
Closed
Description
tl;dr; this is a proposal to standardize the API definitions of function calls that may return buffered values, Node.js Streams or pull-streams.
I'll make this proposal and succinct as possible, with the hopes we can get around it asap.
Our current needs and requirements:
- Users want to be able to consume data coming from calls (i.e: files.{cat, get, ls}) as a single result value. It is extremely convinient.
- We know that buffering everything doesn't work for a big part of the cases.
- We like to use pull-streams everywhere because it saves us from some Node.js hiccups and makes it extremely convenient between modules.
- Users still to have access to Node.js Streams, since they are the most widely use.
- We have a strong commitment to not breaking user-space, however, if this standardization proves to be popular and more user-friendly, I believe we can open an exception as long as we don't loose functionality (only some name changing), under the condition to have a smooth transition.
Essentially we have two options on the table
a) Use option arguments to specify what we are looking for
ipfs.files.cat(cid, {
buffer: true // buffer all the results and return a single value
// PStream: true // return a Pull-Stream
// NStream: true // return a Node.js Stream
}, callback)
b) Use different method names
ipfs.files.cat(cid, callback)
// or
ipfs.files.catPStream(cid)
// or
ipfs.files.catNStream(cid)
This option has a couple of advantages:
- interpreter friendly - by having a method for each type, it will enable V8 to optimize it better
- comparing to what we have today, it will enable the functions that return streams to return streams, instead of the 'callback with a stream'. Enabling things like
ipfs.files.catNStream(cid).pipe(process.stdout)
without going into callback. (The reason why we had to return a stream in a callback, was because of Promises, but that stays onipfs.files.cat
only.
Once this proposal goes forward we need to:
- Update the API definitions
- Update the tests
- Update the implementations
- Update the internals that exposes pull-streams with something like
getStream
, to begetPStream
.