RangerMauve / hypercore-fetch

Implementation of Fetch that uses the Hyper SDK for loading p2p content
MIT License
37 stars 13 forks source link

Interface for hypercore #7

Open RangerMauve opened 4 years ago

RangerMauve commented 4 years ago

It'd be cool if we could detect whether a hyper:// URL was a raw hypercore and change what the path means in that case.

Potentially, we could look at the first block in the hypercore, and if it's a hyperdrive before interpreting it as such, and if not it'll interpret it as a raw hypercore.

I think a hypercore interface would be similar to hyperdrive, but a bit more simple.

// Get a single chunk out
GET /{index} => buffer

// Append a chunk to the log
POST / {body} => 200 OK

// Get data for chunks between a range
GET /{start}...{end} => buffer

// Get the latest chunk in the hypercore
GET /head => buffer

It doesn't need a PUT or DELETE method since hypercores are immutable.

I'm not sure if there's a safe way to specify a content type since it's assumed to just be binary in hypercore unless the application already knows what it is. 🤷

In addition, I think the length should be put into the ETAG header.

I think all the extension message stuff could stay the same as in hyperdrive.