-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Allow ipfs.files.cat to return slices of files #1231
feat: Allow ipfs.files.cat to return slices of files #1231
Conversation
@achingbrain this is phenomenal. Lot's of great stuff in this example, in fact, some of it should be merged into core. It has been requested to have the
This should be something that is provided by the unixfs-engine itself. Would you like to work on that? |
Sure, I'll take a look :) |
I think - though I’m not certain - that there is a mistake in offsetStream line 189 in The parameters to this function aren’t commented (would be good to) but endByte appears to be the byte AFTER the one you want, since you’ve incremented it at line 89 in playByLinks If I understand the Note I have NOT checked the rest of the code in case the same problem exists elsewhere. By the way, as an example it would be super useful to comment the parameters to functions, since as I’m trying to modify it for our needs I’m having to guess some of what you are doing and because of the lack of comments it took me a while to figure out the test above didn’t make sense. |
@mitra42 if you are working on cleaning this up into a proper bundle and are interested in open sourcing that effort, I'd be happy to contribute |
@paralin What we are doing (at archive.org) is open-source, but I haven't pushed it to our repo because I haven't been able to get my version of this to work. I'm trying to use the example to fix the problems we were having using IPFS streams with the Video tag, which means I'm having use a modified version of this code in order to get the asynchronicity to work. I'm using playByLinks which looks like the right approach, (the other versions seem far too inefficient for the The biggest issue is that the I'm not using object.data anywhere else in my code, so I don't know if the code in this example is working (implying I've made a mistake adapting) or if the example also fails in which case maybe we've both made a mistake, or the js-ipfs docs for this function aren't correct. Are you able to get the example here to work ? |
Doesn't seem to work at the moment, due to some SSL issues (happens just after I run webpack) |
Looks like a different problem than the one I'm struggling with. |
In isolating the test, I seem to have discovered a problem with files.cat and object.links/object.data which I've posted as #1258 so the problem might not be in the code of this example. |
FWIW most of the code in this example will go away once ipfs-inactive/js-ipfs-unixfs-engine#202 is merged as it moves the offset stream logic into core. |
@achingbrain - looks like ipfs-inactive/js-ipfs-unixfs-engine#202 will probably need some glue as well to work with a video tag. |
8f8c539
to
5e6d710
Compare
5e6d710
to
1601f6f
Compare
The scope of this PR has changed a bit so I've updated the title & description to reflect that. @mitra42 could you elaborate a bit? What extra glue is required? |
1601f6f
to
580c1f3
Compare
@achingbrain - I’m a little confused, because my comment #1231 (comment) above, referred to some code which was a demo of 3 or 4 ways to pull a slice of a file, including one that used obj.links and obj.data (which I copied and adapted), another that read using files.cat and ignored earlier bytes and so on. Strangely I can’t find that base code in this PR any more, so either I made this bug report on the wrong pull request, or the commit got replaced which I didn’t think possible? I’d think I’d been hallucinating, but I coped the code and made a bug report on it 😃 My comment about glue refers to whatever code we used having to be attached to an (existing) video tag, I didn't see any code that would enable you to do that in ipfs-inactive/js-ipfs-unixfs-engine#202 (and wasn't expecting any) but I now see an example in this commit based on videostream and that was the kind of code I was referring to. We actually are using the RenderMedia package which wraps video stream and needs to be passed a createReadStream function in the same form as you do here, ( https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options - in particular an {start, end} parameter where end is the last byte wanted), so that should work fine. Should we expect the change to catReadableStream to land in js-ipfs v0.28.3 or is it further away? |
Aha, ok - this PR has been evolving over time a little so the confusion is understandable, sorry about that. A lot of the code has moved into core so hopefully the example is now a bit easier to follow at least. I'm hoping it'll be in the next release but it depends on when people get the time to review it. |
b76eb50
to
9f5b933
Compare
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.
It is missing the HTTP-API endpoint update and the CLI command as well.
b9b2564
to
9ff4b79
Compare
@diasdavid http/cli commands should be there now but needs ipfs-inactive/js-ipfs-http-client#734 to be merged |
Would be good to get this and ipfs-inactive/js-ipfs-http-client#734 merged as the interface-ipfs-core PR has already been merged |
ipfs-inactive/js-ipfs-unixfs-engine#209 needs to be merged too |
@achingbrain what's missing on this one? |
@diasdavid It's waiting for js-ipfs-api to be released |
@achingbrain please rebase master onto this branch. you should be fully unblocked. |
9ff4b79
to
4eb89a5
Compare
feat: Allows for byte offsets when using ipfs.files.cat and friends to request slices of files
4eb89a5
to
e33e668
Compare
@achingbrain got it (the problem when PRs dangle for too long) We can solve it by merging both PRs into one. |
@achingbrain looks like ipfs-inactive/js-ipfs-unixfs-engine#207 (which appears to supersede ipfs-inactive/js-ipfs-unixfs-engine#202) got merged, does that mean the example in here no longer reflect the correct/most succinct API? |
@parkan take a look at the example in https://github.com/ipfs/js-ipfs/tree/master/examples/browser-readablestream - it shows how to use |
Is that in a released version now? |
@mitra42 looks like v0.29.* should have it |
This PR exposes the
begin
/end
arguments from ipfs-inactive/js-ipfs-unixfs-engine#207 in the ipfs.files.cat* methods to return slices of files. It also includes an example of how to stream video from ipfs to the browser using thevideostream
module.Requires ipfs-inactive/js-ipfs-unixfs-engine#207 to be merged first.