-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
66 lines (49 loc) · 1.58 KB
/
test.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const getFile = async () => {
const hash = cid;
console.log(cid);
if (!hash) {
return console.log("Error : no id");
}
const ipfsPath = "QmWXdjNC362aPDtwHPUE9o2VMqPeNeCQuTBTv1NsKtwypg"; // text file in folder
const id = 'Qmegw7TLhgkTMKQNeNrngsxFueepAuwUYXKmZHQutEoe7D' // Encrypted file
const ipfsPath2 = "QmPChd2hVbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68A" // text file direct;
/* for await (const chunk of ipfs.cat(ipfsPath)) {
console.info(chunk)
} */
/* for await (const buf of ipfs.get(id)) {
const blob = new Blob([buf]);
console.log(blob);
} */
/* for await (const file of ipfs.ls(id)) {
if (file.content) {
console.log(file.content);
const content = uint8ArrayConcat(await all(file.content))
console.log(content);
}
} */
let path = "";
for await (const file of ipfs.ls(id)) {
console.log(file.path)
path = file.path;
}
/* const stream = ipfs.cat(path);
let data = ''
for await (const chunk of stream) {
// chunks of data are returned as a Buffer, convert it back to a string
data += chunk.toString()
}
console.log(data) */
const fileContents = await toBuffer(ipfs.cat(path))
const message = fileContents.toString()
console.log(message);
console.log("start");
const blob = new Blob([message]);
var file = new File([blob], "x.text");
console.log(file);
var fr = new FileReader();
fr.onload = function () {
console.log(fr.result);
}
fr.readAsText(file)
console.log("End");
}