|
1 |
| -import fs from 'fs' |
2 |
| -import { DataSourceFile } from '.' |
3 |
| -import IPFS from 'ipfs-core' |
| 1 | +// import fs from 'fs' |
| 2 | +// import { DataSourceFile } from '.' |
| 3 | +// import IPFS from 'ipfs-core' |
4 | 4 |
|
5 |
| -/** |
6 |
| - * Storage on the distributed web {@link https://ipfs.io} |
7 |
| - */ |
8 |
| -export class DataSourceIpfs extends DataSourceFile { |
9 |
| - constructor(map, name, options = {}) { |
10 |
| - super(map, name, options) |
11 |
| - } |
| 5 | +// /** |
| 6 | +// * Storage on the distributed web {@link https://ipfs.io} |
| 7 | +// */ |
| 8 | +// export class DataSourceIpfs extends DataSourceFile { |
| 9 | +// constructor(map, name, options = {}) { |
| 10 | +// super(map, name, options) |
| 11 | +// } |
12 | 12 |
|
13 |
| - async save(id, data) { |
14 |
| - super.save(id, data) |
15 |
| - this.writeFile() |
16 |
| - return data |
17 |
| - } |
| 13 | +// async save(id, data) { |
| 14 | +// super.save(id, data) |
| 15 | +// this.writeFile() |
| 16 | +// return data |
| 17 | +// } |
18 | 18 |
|
19 |
| - async find(id) { |
20 |
| - return super.find(id) |
21 |
| - } |
| 19 | +// async find(id) { |
| 20 | +// return super.find(id) |
| 21 | +// } |
22 | 22 |
|
23 |
| - startIpfs() { |
24 |
| - try { |
25 |
| - IPFS.create({ |
26 |
| - repo: 'aegis-' + Math.random(), |
27 |
| - }).then(fs => (this.ipfs = fs)) |
28 |
| - } catch (err) { |
29 |
| - console.error(err) |
30 |
| - } |
31 |
| - } |
| 23 | +// startIpfs() { |
| 24 | +// try { |
| 25 | +// IPFS.create({ |
| 26 | +// repo: 'aegis-' + Math.random(), |
| 27 | +// }).then(fs => (this.ipfs = fs)) |
| 28 | +// } catch (err) { |
| 29 | +// console.error(err) |
| 30 | +// } |
| 31 | +// } |
32 | 32 |
|
33 |
| - load(hydrate) { |
34 |
| - this.startIpfs() |
35 |
| - if (fs.existsSync(this.file)) { |
36 |
| - try { |
37 |
| - this.cid = fs.readFileSync(this.file, 'utf-8') |
38 |
| - this.readFile(hydrate) |
39 |
| - } catch (error) { |
40 |
| - console.error(this.load.name, error.message) |
41 |
| - } |
42 |
| - } else { |
43 |
| - return new Map() |
44 |
| - } |
45 |
| - } |
| 33 | +// load(hydrate) { |
| 34 | +// this.startIpfs() |
| 35 | +// if (fs.existsSync(this.file)) { |
| 36 | +// try { |
| 37 | +// this.cid = fs.readFileSync(this.file, 'utf-8') |
| 38 | +// this.readFile(hydrate) |
| 39 | +// } catch (error) { |
| 40 | +// console.error(this.load.name, error.message) |
| 41 | +// } |
| 42 | +// } else { |
| 43 | +// return new Map() |
| 44 | +// } |
| 45 | +// } |
46 | 46 |
|
47 |
| - async readFile(hydrate) { |
48 |
| - try { |
49 |
| - let data |
50 |
| - const stream = this.ipfs.cat(this.cid) |
51 |
| - for await (const chunk of stream) { |
52 |
| - // chunks of data are returned as a Buffer, convert it back to a string |
53 |
| - data += chunk.toString() |
54 |
| - } |
55 |
| - return hydrate(new Map(JSON.parse(data), this.revive)) |
56 |
| - } catch (e) { |
57 |
| - console.error(e) |
58 |
| - } |
59 |
| - } |
| 47 | +// async readFile(hydrate) { |
| 48 | +// try { |
| 49 | +// let data |
| 50 | +// const stream = this.ipfs.cat(this.cid) |
| 51 | +// for await (const chunk of stream) { |
| 52 | +// // chunks of data are returned as a Buffer, convert it back to a string |
| 53 | +// data += chunk.toString() |
| 54 | +// } |
| 55 | +// return hydrate(new Map(JSON.parse(data), this.revive)) |
| 56 | +// } catch (e) { |
| 57 | +// console.error(e) |
| 58 | +// } |
| 59 | +// } |
60 | 60 |
|
61 |
| - async writeFile() { |
62 |
| - try { |
63 |
| - // add your data to to IPFS - this can be a string, a Buffer, |
64 |
| - // a stream of Buffers, etc |
65 |
| - const { cid } = this.ipfs.add(JSON.stringify([...this.dsMap])) |
66 |
| - fs.writeFileSync(this.file, cid.toString()) |
67 |
| - this.cid = cid |
68 |
| - } catch (error) { |
69 |
| - console.error(error) |
70 |
| - } |
71 |
| - } |
72 |
| -} |
| 61 | +// async writeFile() { |
| 62 | +// try { |
| 63 | +// // add your data to to IPFS - this can be a string, a Buffer, |
| 64 | +// // a stream of Buffers, etc |
| 65 | +// const { cid } = this.ipfs.add(JSON.stringify([...this.dsMap])) |
| 66 | +// fs.writeFileSync(this.file, cid.toString()) |
| 67 | +// this.cid = cid |
| 68 | +// } catch (error) { |
| 69 | +// console.error(error) |
| 70 | +// } |
| 71 | +// } |
| 72 | +// } |
0 commit comments