deno.land / x / swarm_gates@0.0.1 / mod.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445export 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}`); }); }}
Version Info
External Dependencies