-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support iterators and async iterators #2
Conversation
This allows us to accept async interators as arguments to `ipfs.add` and friends. It also allows adding plain old js things like strings and arrays, so hooray for that.
PR from my own fork 'cos I don't have push access to this repo. |
@@ -14,6 +14,8 @@ const expect = chai.expect | |||
|
|||
describe('add-input-validation', function () { | |||
it('validates correct primitive input types', function () { | |||
expect(validate('Hello world')).to.be.true() | |||
expect(validate([0, 1, 2, 3])).to.be.true() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ test for async iterator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@achingbrain there are some lint warnings causing this to fail in CI |
Should be all good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achingbrain what you wanna do about pull-streams
? should it be removed too ?
@@ -24,7 +22,7 @@ const validateAddInput = (input) => { | |||
if (isInput(input) || (Array.isArray(input) && input.every(isInput))) { | |||
return true | |||
} else { | |||
throw new Error(`Input not supported. Expected Buffer|ReadableStream|PullStream|File|Array<Object> got ${kindOf(input)}. Check the documentation for more info https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#add`) | |||
throw new Error(`Input not supported. Expected Buffer|ReadableStream|PullStream|File|Array<Object>| got ${kindOf(input)}. Check the documentation for more info https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#add`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error(`Input not supported. Expected Buffer|ReadableStream|PullStream|File|Array<Object>| got ${kindOf(input)}. Check the documentation for more info https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#add`) | |
throw new Error(`Input not supported. Expected Iterator|AsyncIterator|PullStream|File|Array<Object>| got ${kindOf(input)}. Check the documentation for more info https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#add`) |
Closing in favour of #6 which from a branch in this repo.. |
This allows us to accept async interators as arguments to
ipfs.add
and friends.It also allows adding plain old js things like strings and arrays, so hooray for that.