Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

docs(example): show folks how to use pull-streams instead #988

Closed
wants to merge 1 commit into from

Conversation

dignifiedquire
Copy link
Member

Always stream incoming data through pull streams and use browserify-aes directly from master now. I was able to add a 300Mb sized file with this quite quickly.

Fixes most issues in #952 I believe

@@ -62,7 +62,7 @@
</div>

<!-- The IPFS node module -->
<script src="//unpkg.com/ipfs/dist/index.min.js"></script>
<!-- <script src="//unpkg.com/ipfs/dist/index.min.js"></script> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was supposed to be the example that showed that "no extra batteries required". Kind of sad we lost that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid unpkg doesn't allow linking to a branch? We could also publish latest master ourselves on IPFS and link that instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to keep this, with the new release that would be fine to use the unkpkg version again

path: file.name,
content: pullFilereader(file)
}]),
node.files.createAddPullStream(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, but we shouldn't have examples with undocumented (and already agreed to change) API

Needs this solved first. ipfs-inactive/interface-js-ipfs-core#126

@daviddias
Copy link
Member

Awesome job @dignifiedquire! I'll keep this PR open until #988 (comment) is solved

@victorb
Copy link
Member

victorb commented Sep 4, 2017

Hm, a bit worried about this as most people haven't been exposed to pull-streams and we're supposed to support the API that most people use as well. This seems to amount to that even though you can use js-ipfs without using pull-streams, it's really inefficient and you should probably use pull-streams.

As this is supposed to be a simple example, I'm wondering if it's not best to stick with the non-pullstreams version.

@victorb
Copy link
Member

victorb commented Sep 4, 2017

Maybe we could show it's done with non-pullstreams in comments (risk of having code that is not being run though, might not actually work...) or make the pullstream into a separate example for better performance. We don't want to alienate people who see a js-ipfs example for the first time.

@dignifiedquire
Copy link
Member Author

We are currently alienating people with the browser crashing, so I think having pull-streams is much better than crashing and being slow. node streams are really not meant to be used in the browser in most situations I don't think it's good to show examples with them, rather use non streaming methods by default and educate users about better options

@daviddias
Copy link
Member

We will have both API and once they are properly documented, we can use them in the examples. This is one of the priorities for 0.27 (and probably the target thing to get it released)

Always stream incoming data through pull streams and use browserify-aes directly from master now. I was able to add a 300Mb sized file with this quite quickly.
@daviddias daviddias mentioned this pull request Sep 11, 2017
16 tasks
@daviddias daviddias added status/ready Ready to be worked P0 Critical: Tackled by core team ASAP and removed status/ready Ready to be worked labels Oct 13, 2017
@daviddias daviddias added status/in-progress In progress and removed status/ready Ready to be worked labels Oct 22, 2017
@daviddias daviddias changed the title docs(example): improve exchange example docs(example): show folks how to use pull-streams instead Oct 22, 2017
@daviddias
Copy link
Member

Actively working on ipfs-inactive/interface-js-ipfs-core#162 this week to then finish up this PR

@daviddias
Copy link
Member

Who was interested on this PR, please review ipfs-inactive/interface-js-ipfs-core#162 (comment)

@daviddias daviddias self-assigned this Nov 6, 2017
@daviddias
Copy link
Member

Redirecting the efforts here to this PR #1086

@daviddias daviddias closed this Nov 17, 2017
@ghost ghost removed the status/in-progress In progress label Nov 17, 2017
@daviddias daviddias deleted the example/better-exchange branch November 17, 2017 13:32
@mitra42
Copy link

mitra42 commented Nov 17, 2017

@diasdavid - it would be useful to leave issues open until they are solved, even if the solution is elsewhere. I for one have been watching this thread in the hope of finding the docs implied by its title, " show folks how to use pull-streams instead " with the direction to #1086 , I can't find any answer to this question in that issue nor in ipfs-inactive/interface-js-ipfs-core#162, and I'm probably not the only one waiting on docs before converting app code to use pull-streams.

@daviddias
Copy link
Member

@mitra42 valid point. I tend to keep issues and PR open until they are fixed or converge elsewhere. It is hard to keep track of multiple issues discussing the same things and that is why I always leave a pointer saying that "x discussion continues at issue y".

@mitra42, for your case, ipfs-inactive/interface-js-ipfs-core#162 brought you something even better as you won't have to worry about pull-streams and just use ipfs.files.add with files and get hashes back. See the updated https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add

See the updated example on #1086 that this PR was also updating (direct link here

function onDrop (event) {
onDragExit()
$errors.className = 'hidden'
event.preventDefault()
if (!node) {
return onError('IPFS must be started before files can be added')
}
const dt = event.dataTransfer
const filesDropped = dt.files
function readFileContents (file) {
return new Promise((resolve) => {
const reader = new window.FileReader()
reader.onload = (event) => resolve(event.target.result)
reader.readAsArrayBuffer(file)
})
}
for (let i = 0; i < filesDropped.length; i++) {
const file = filesDropped[i]
readFileContents(file)
.then((buffer) => {
node.files.add(Buffer.from(buffer), (err, filesAdded) => {
if (err) { return onError(err) }
const fl = filesAdded[0]
$multihashInput.value = fl.hash
$filesStatus.innerHTML = `Added ${file.name} as ${fl.hash}`
})
})
.catch(onError)
}
}
), as you will see there are no Readable or Pull Streams involved. I used this code files bigger than 750Mb, a significant improvement.

@mitra42
Copy link

mitra42 commented Nov 17, 2017

Email sent as this goes into multiple topics.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P0 Critical: Tackled by core team ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants