deno.land / x / swarm_gates@0.0.1 / mod.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
export default class SwarmGate { constructor( public readonly host: string, ) {}
//TODO //Check if hash is valid async download(hash: string): Promise<Uint8Array> { return fetch(`${this.host}/bzz-raw:/${hash}`) .then((response) => { if (response.ok) { return response.arrayBuffer() .then((x) => new Uint8Array(x)); } throw new Error(`Request failed with status ${response.status}`); }); }
//TODO //There must be a better way to check swarm node availability async isAvailable(): Promise<boolean> { return !!await this.upload(new Uint8Array([1])); }
async upload(file: Uint8Array): Promise<string> { if (!(file instanceof Uint8Array)) { throw new Error("The data to upload must be an Uint8Array data set"); } if (file.length === 0) { throw new Error("The data to upload can't be an empty data set"); }
return fetch(`${this.host}/bzz-raw:`, { body: file, method: "POST", }) .then((response) => { if (response.ok) { return response.text(); } throw new Error(`Request failed with status ${response.status}`); }); }}
swarm_gates

Version Info

Tagged at
3 years ago

External Dependencies

No external dependencies 🎉