nanoseek
所属分类:GPT/ChatGPT
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2023-11-08 17:29:40
上 传 者:
sh-1993
说明: UHRP下载器
(UHRP Downloader)
文件列表:
.eslintrc.json (365, 2023-12-24)
getUrlFromQueryResult.js (760, 2023-12-24)
index.js (4913, 2023-12-24)
nanoseek.test.js (6814, 2023-12-24)
package-lock.json (1206105, 2023-12-24)
package.json (946, 2023-12-24)
# NanoSeek
UHRP Downloader
## Overview
This library allows you to download content from the Universal Hash Resolution Protocol (UHRP). Since UHRP URLs are content-addressed, they are self-authenticating. Since any UHRP host can advertise the availability of content, discovery is no longer controlled by a trusted third party as is the case with HTTP.
## Example
For an example in React, check out the [NanoStore UI](https://github.com/p2ppsr/nanostore-ui), or [view it on the web](https://nanostore-ui.babbage.systems).
The below code can be used in a browser to download a UHRP file, given the URL:
```js
const { download } = require('nanoseek')
// URL of the file you want to download
const downloadURL = 'XUTTCy7KcAn1MdU8SksihCqTnzXc76gbWNXqVMJ5rN1swFTbqbbV'
// The confederacy host URL
const host = 'https://confederacy.babbage.systems'
const { mimeType, data } = await download({
UHRPUrl: downloadURL,
confederacyHost: host })
// Create a Blob and download the file with the browser
const blob = new Blob([data], { type: mimeType })
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = downloadURL // Or provide the file name you want to use
link.click()
```
## API
#### Table of Contents
* [resolve](#resolve)
* [Parameters](#parameters)
* [download](#download)
* [Parameters](#parameters-1)
* [getUrlFromQueryResult](#geturlfromqueryresult)
* [Parameters](#parameters-2)
### resolve
Locates HTTP URLs where content can be downloaded. It uses the passed Confederacy hosts or the default one.
#### Parameters
* `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** All parameters are passed in an object. (optional, default `{}`)
* `obj.UHRPUrl` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The UHRP url to resolve.
* `obj.confederacyHost` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** HTTPS URL for for the Confederacy host with default setting. (optional, default `'https://confederacy.babbage.systems'`)
* `obj.clientPrivateKey` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Key used to resolve the file (for payment)
* Throws **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** If UHRP url parameter invalid or Confederacy hosts is not an array
or there is an error retrieving url(s) stored in the UHRP token.
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** An array of HTTP URLs where content can be downloaded.
### download
Downloads content from a UHRP url and returns it as a buffer with its mime type, after validating that the hash is correct. It uses the passed Confederacy hosts or the default one.
#### Parameters
* `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** All parameters are passed in an object. (optional, default `{}`)
* `obj.UHRPUrl` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The UHRP url to download.
* `obj.confederacyHost` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The confederacy host URL (optional, default `'https://confederacy.babbage.systems'`)
* `obj.clientPrivateKey` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Key used to resolve the file (for payment)
* Throws **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** If UHRP url parameter invalid or Confederacy hosts is not an array or hash is invalid or unable to download using retrieved url(s)
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An object containing "data" (a buffer) and "mimeType" for the content.
### getUrlFromQueryResult
This function takes a query result and returns the associated url(s).
#### Parameters
* `queryResult` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The query result to parse.
* Throws **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** If passed parameter query result is missing or an invalid type.
Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The retrieved url(s).
## License
The license for the code in this repository is the Open BSV License.
近期下载者:
相关文件:
收藏者: