ferristseng / rust-ipfs-api

IPFS HTTP client in Rust
Apache License 2.0
246 stars 68 forks source link

File Seeks With client.cat #103

Closed amiller68 closed 2 years ago

amiller68 commented 2 years ago

Hi, I want to implement File Seeks with client.cat. For example, I'd like to request a range of bytes from an endpoint rather than the whole file. I know this is possible with js-ipfs, and probably could be implemented by incorporating a 'range' header in the client's request to an endpoint. Could anyone either offer me a way to do this with the repository as is or lay out steps for implementing this? I am new to Rust and not sure where to start looking.

SionoiS commented 2 years ago

Hi!

First you would have to add more option to the request.

https://github.com/ferristseng/rust-ipfs-api/blob/master/ipfs-api-prelude/src/request/cat.rs https://docs.ipfs.io/reference/kubo/rpc/#api-v0-cat

In this case I don't think streaming progress would work but you might want to check yourself.

Then write some tests for it I guess. Sorry can't be more helpful it's been some time.

amiller68 commented 2 years ago

In this case I don't think streaming progress would work but you might want to check yourself.

What do you mean by that?

amiller68 commented 2 years ago

Working on this here: https://github.com/banyancomputer/rust-ipfs-api

SionoiS commented 2 years ago

@amiller68 I would not change the name of the request. Instead make the options.. well optional.

Check the IPFS docs it tells you what arguments are required or not. Might help you get a PR merged.

Otherwise :+1:

amiller68 commented 2 years ago

@SionoiS I'm v new to Rust but my understanding is creating a new function declaration for optional arguments is not atypical/a technique that is featured in the code I forked (e.g. files_read vs files_read_with_options, ls vs ls_with_options). Do you think it would help to redeclare cat_bytes as cat_with_options or something?

amiller68 commented 2 years ago

Other than that my Doc tests pass and independently tested the implementation in a separate repo

SionoiS commented 2 years ago

I'm not the maintainer but I think following the API as close as possible is better. :shrug:

Take a look at Add https://github.com/ferristseng/rust-ipfs-api/blob/master/ipfs-api-prelude/src/request/add.rs

The request is full on Options and the add functions can differ but use the same request.

Otherwise it looks good to me.