Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 0d9ede4

Browse files
dignifiedquiredaviddias
authored andcommitted
refactor: move to pull-streams internally
Closes #403
1 parent fa2c807 commit 0d9ede4

File tree

68 files changed

+300
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+300
-308
lines changed

package.json

+28-21
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@
4040
},
4141
"homepage": "https://github.com/ipfs/js-ipfs#readme",
4242
"devDependencies": {
43-
"aegir": "^8.0.0",
43+
"aegir": "^8.0.1",
4444
"buffer-loader": "0.0.1",
4545
"chai": "^3.5.0",
4646
"expose-loader": "^0.7.1",
47-
"form-data": "^1.0.0-rc4",
47+
"form-data": "^1.0.1",
48+
"fs-pull-blob-store": "^0.3.0",
4849
"gulp": "^3.9.1",
4950
"idb-plus-blob-store": "^1.1.2",
50-
"interface-ipfs-core": "^0.14.3",
51+
"idb-pull-blob-store": "^0.4.0",
52+
"interface-ipfs-core": "^0.14.4",
5153
"left-pad": "^1.1.1",
52-
"lodash": "^4.14.1",
54+
"lodash": "^4.15.0",
5355
"ncp": "^2.0.0",
5456
"nexpect": "^0.5.0",
5557
"pre-commit": "^1.1.3",
@@ -60,45 +62,50 @@
6062
"dependencies": {
6163
"babel-runtime": "^6.11.6",
6264
"bl": "^1.1.2",
63-
"boom": "^3.2.2",
65+
"boom": "^4.0.0",
6466
"bs58": "^3.0.0",
6567
"debug": "^2.2.0",
6668
"detect-node": "^2.0.3",
67-
"fs-blob-store": "^5.2.1",
68-
"glob": "^7.0.5",
69+
"glob": "^7.0.6",
6970
"hapi": "^15.0.3",
7071
"ipfs-api": "^8.0.3",
71-
"ipfs-bitswap": "^0.6.0",
72+
"ipfs-bitswap": "^0.7.0",
7273
"ipfs-block": "^0.3.0",
73-
"ipfs-block-service": "^0.4.0",
74-
"ipfs-merkle-dag": "^0.6.2",
74+
"ipfs-block-service": "^0.5.0",
75+
"ipfs-merkle-dag": "^0.7.0",
7576
"ipfs-multipart": "^0.1.0",
76-
"ipfs-repo": "^0.8.0",
77+
"ipfs-repo": "^0.9.0",
7778
"ipfs-unixfs": "^0.1.4",
78-
"ipfs-unixfs-engine": "^0.10.1",
79+
"ipfs-unixfs-engine": "^0.11.2",
7980
"isstream": "^0.1.2",
8081
"joi": "^9.0.4",
81-
"libp2p-ipfs": "^0.12.1",
82-
"libp2p-ipfs-browser": "^0.12.1",
83-
"lodash.get": "^4.4.1",
82+
"libp2p-ipfs": "^0.13.0",
83+
"libp2p-ipfs-browser": "^0.14.0",
84+
"lodash.get": "^4.4.2",
8485
"lodash.has": "^4.5.2",
85-
"lodash.set": "^4.3.1",
86-
"lodash.sortby": "^4.6.1",
87-
"mafmt": "^2.1.1",
86+
"lodash.set": "^4.3.2",
87+
"lodash.sortby": "^4.7.0",
88+
"mafmt": "^2.1.2",
8889
"map-limit": "0.0.1",
89-
"multiaddr": "^2.0.2",
90+
"multiaddr": "^2.0.3",
9091
"multihashes": "^0.2.2",
9192
"path-exists": "^3.0.0",
9293
"peer-book": "^0.3.0",
9394
"peer-id": "^0.7.0",
94-
"peer-info": "^0.7.0",
95+
"peer-info": "^0.7.1",
9596
"promisify-es6": "^1.0.1",
97+
"pull-file": "^1.0.0",
98+
"pull-paramap": "^1.1.6",
99+
"pull-sort": "^1.0.0",
100+
"pull-stream": "^3.4.5",
101+
"pull-stream-to-stream": "^1.3.3",
102+
"pull-zip": "^2.0.0",
96103
"read-pkg-up": "^1.0.1",
97-
"readable-stream": "1.1.13",
98104
"run-parallel": "^1.1.6",
99105
"run-parallel-limit": "^1.0.3",
100106
"run-series": "^1.1.4",
101107
"run-waterfall": "^1.1.3",
108+
"stream-to-pull-stream": "^1.7.0",
102109
"temp": "^0.8.3",
103110
"through2": "^2.0.1",
104111
"update-notifier": "^1.0.2",

src/cli/commands/files/add.js

+40-65
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const fs = require('fs')
88
const path = require('path')
99
const glob = require('glob')
1010
const sortBy = require('lodash.sortby')
11-
const mapLimit = require('map-limit')
11+
const pull = require('pull-stream')
12+
const pullFile = require('pull-file')
13+
const paramap = require('pull-paramap')
14+
const zip = require('pull-zip')
1215

1316
function checkPath (inPath, recursive) {
1417
// This function is to check for the following possible inputs
@@ -48,76 +51,48 @@ module.exports = {
4851
},
4952

5053
handler (argv) {
51-
let inPath = checkPath(argv.file, argv.recursive)
54+
const inPath = checkPath(argv.file, argv.recursive)
55+
const index = inPath.lastIndexOf('/') + 1
56+
57+
utils.getIPFS((err, ipfs) => {
58+
if (err) throw err
59+
60+
glob(path.join(inPath, '/**/*'), (err, list) => {
61+
if (err) throw err
62+
if (list.length === 0) list = [inPath]
63+
64+
pull(
65+
zip(
66+
pull.values(list),
67+
pull(
68+
pull.values(list),
69+
paramap(fs.stat.bind(fs), 50)
70+
)
71+
),
72+
pull.map((pair) => ({
73+
path: pair[0],
74+
isDirectory: pair[1].isDirectory()
75+
})),
76+
pull.filter((file) => !file.isDirectory),
77+
pull.map((file) => ({
78+
path: file.path.substring(index, file.path.length),
79+
content: pullFile(file.path)
80+
})),
81+
ipfs.files.createAddPullStream(),
82+
pull.map((file) => ({
83+
hash: file.hash,
84+
path: file.path
85+
})),
86+
pull.collect((err, added) => {
87+
if (err) throw err
5288

53-
utils.getIPFS(gotIPFS)
54-
55-
function gotIPFS (err, ipfs) {
56-
if (err) {
57-
throw err
58-
}
59-
60-
glob(path.join(inPath, '/**/*'), (err, res) => {
61-
if (err) {
62-
throw err
63-
}
64-
65-
ipfs.files.createAddStream((err, i) => {
66-
if (err) {
67-
throw err
68-
}
69-
const added = []
70-
71-
i.on('data', (file) => {
72-
added.push({
73-
hash: file.hash,
74-
path: file.path
75-
})
76-
})
77-
78-
i.on('end', () => {
7989
sortBy(added, 'path')
8090
.reverse()
8191
.map((file) => `added ${file.hash} ${file.path}`)
8292
.forEach((msg) => console.log(msg))
8393
})
84-
85-
if (res.length === 0) {
86-
res = [inPath]
87-
}
88-
89-
const writeToStream = (stream, element) => {
90-
const index = inPath.lastIndexOf('/') + 1
91-
i.write({
92-
path: element.substring(index, element.length),
93-
content: fs.createReadStream(element)
94-
})
95-
}
96-
97-
mapLimit(res, 50, (file, cb) => {
98-
fs.stat(file, (err, stat) => {
99-
if (err) {
100-
return cb(err)
101-
}
102-
return cb(null, {
103-
path: file,
104-
isDirectory: stat.isDirectory()
105-
})
106-
})
107-
}, (err, res) => {
108-
if (err) {
109-
throw err
110-
}
111-
112-
res
113-
.filter((elem) => !elem.isDirectory)
114-
.map((elem) => elem.path)
115-
.forEach((elem) => writeToStream(i, elem))
116-
117-
i.end()
118-
})
119-
})
94+
)
12095
})
121-
}
96+
})
12297
}
12398
}

src/cli/commands/init.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const IpfsRepo = require('ipfs-repo')
44
const Ipfs = require('../../core')
5-
const fsBlobStore = require('fs-blob-store')
5+
const Store = require('fs-pull-blob-store')
66
const utils = require('../utils')
77

88
module.exports = {
@@ -33,7 +33,7 @@ module.exports = {
3333
const path = utils.getRepoPath()
3434

3535
const repo = new IpfsRepo(path, {
36-
stores: fsBlobStore
36+
stores: Store
3737
})
3838

3939
const ipfs = new Ipfs(repo)

src/core/default-repo/browser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
const idb = require('idb-plus-blob-store')
3+
const Store = require('idb-pull-blob-store')
44
const IPFSRepo = require('ipfs-repo')
55

66
module.exports = (dir) => {
77
const repoPath = dir || 'ipfs'
8-
return new IPFSRepo(repoPath, {stores: idb})
8+
return new IPFSRepo(repoPath, {stores: Store})
99
}

src/core/default-repo/node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

33
const os = require('os')
4-
const fs = require('fs-blob-store')
4+
const Store = require('fs-pull-blob-store')
55
const IPFSRepo = require('ipfs-repo')
66
const path = require('path')
77

88
module.exports = (dir) => {
99
const repoPath = dir || path.join(os.homedir(), '.ipfs')
10-
return new IPFSRepo(repoPath, {stores: fs})
10+
return new IPFSRepo(repoPath, {stores: Store})
1111
}

src/core/ipfs/block.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ module.exports = function block (self) {
77
return {
88
get: (hash, callback) => {
99
hash = cleanHash(hash)
10-
11-
self._blockS.getBlock(hash, callback)
10+
self._blockS.get(hash, callback)
1211
},
1312
put: (block, callback) => {
1413
if (Array.isArray(block)) {
@@ -18,18 +17,18 @@ module.exports = function block (self) {
1817
block = new Block(block)
1918
}
2019

21-
self._blockS.addBlock(block, (err) => {
20+
self._blockS.put(block, (err) => {
2221
callback(err, block)
2322
})
2423
},
2524
del: (hash, callback) => {
2625
hash = cleanHash(hash)
27-
self._blockS.deleteBlock(hash, callback)
26+
self._blockS.delete(hash, callback)
2827
},
2928
stat: (hash, callback) => {
3029
hash = cleanHash(hash)
3130

32-
self._blockS.getBlock(hash, (err, block) => {
31+
self._blockS.get(hash, (err, block) => {
3332
if (err) {
3433
return callback(err)
3534
}

0 commit comments

Comments
 (0)