This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
ipfs.files.exists? #780
Closed
Description
Another possible "exists" request.
I'm working with ipfs.files.cat
and I may have the need to detect whether a hash exists in the local repo before trying to get it from a gateway. Since the browser node isn't autoatically peering and retrieving files from the DHT yet (or I don't know how to manually implement it yet (or both)), I need to create a workflow that's something like:
- Try to attempt to grab the content locally
- Catch the exception and grab it from a dedicated gateway I have hosted on AWS
However, looking at the code for cat
, I see the pull stream calls at the bottom:
pull(
exporter(hash, self._ipldResolver),
pull.collect((err, files) => {
if (err) {
return callback(err)
}
callback(null, toStream.source(files[0].content))
})
)
I don't think that pull.colllect call is fired if the hash doesn't exist, so when I create a promise chain like below, it never fails or resolves.
this.ipfs.files.cat(e.detail)
.then(this._processObjectStream)
.then(this._fireBodyEvent.bind(this, "file-read"))
.catch(this._getFileFromServer.bind(this));
Not sure exactly how to proceed. Any advice or workaround is appreciated. Thank you!