Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit f942e76

Browse files
committed
Add "addFiles" API.
1 parent 6c22cd5 commit f942e76

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

src/add-to-dagnode-transform.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const async = require('async')
24
const getDagNode = require('./get-dagnode')
35

src/api/add-files.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const addToDagNodesTransform = require('../add-to-dagnode-transform')
4+
5+
module.exports = (send) => {
6+
return function add (path, opts, cb) {
7+
if (typeof (opts) === 'function' && cb === undefined) {
8+
cb = opts
9+
opts = {}
10+
}
11+
12+
if (typeof (path) !== 'string') {
13+
return cb(new Error('"path" must be a string'))
14+
}
15+
16+
var sendWithTransform = send.withTransform(addToDagNodesTransform)
17+
18+
return sendWithTransform('add', null, opts, path, cb)
19+
}
20+
}

src/api/add-url.js

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

33
const Wreck = require('wreck')
4-
const async = require('async')
5-
const DAGNode = require('ipfs-merkle-dag').DAGNode
64
const addToDagNodesTransform = require('../add-to-dagnode-transform')
75

86
module.exports = (send) => {

src/api/add.js

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

33
const isStream = require('isstream')
4-
const Wreck = require('wreck')
54
const addToDagNodesTransform = require('../add-to-dagnode-transform')
65

76
module.exports = (send) => {

src/get-dagnode.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const DAGNode = require('ipfs-merkle-dag').DAGNode
24

35
module.exports = function (send, hash, cb) {

src/load-commands.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
function requireCommands () {
44
return {
55
add: require('./api/add'),
6+
addFiles: require('./api/add-files'),
67
addUrl: require('./api/add-url'),
78
bitswap: require('./api/bitswap'),
89
block: require('./api/block'),

test/api/add.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (isNode) {
2424
}
2525

2626
describe('.add', () => {
27-
it('add file', (done) => {
27+
it('add buffer as tuple', (done) => {
2828
if (!isNode) {
2929
return done()
3030
}
@@ -74,12 +74,12 @@ describe('.add', () => {
7474
})
7575
})
7676

77-
it('add path', (done) => {
77+
it('local fs: add file', (done) => {
7878
if (!isNode) {
7979
return done()
8080
}
8181

82-
apiClients.a.add(testfilePath, (err, res) => {
82+
apiClients.a.addFiles(testfilePath, (err, res) => {
8383
expect(err).to.not.exist
8484

8585
const added = res[0] != null ? res[0] : res
@@ -90,8 +90,8 @@ describe('.add', () => {
9090
})
9191
})
9292

93-
it('add a nested dir following symlinks', (done) => {
94-
apiClients.a.add(path.join(__dirname, '/../test-folder'), { recursive: true }, (err, res) => {
93+
it('local fs: add nested dir (follow symlinks)', (done) => {
94+
apiClients.a.addFiles(path.join(__dirname, '/../test-folder'), { recursive: true }, (err, res) => {
9595
if (isNode) {
9696
expect(err).to.not.exist
9797

@@ -108,8 +108,8 @@ describe('.add', () => {
108108
})
109109
})
110110

111-
it('add a nested dir without following symlinks', (done) => {
112-
apiClients.a.add(path.join(__dirname, '/../test-folder'), { recursive: true, followSymlinks: false }, (err, res) => {
111+
it('local fs: add nested dir (don\'t follow symlinks)', (done) => {
112+
apiClients.a.addFiles(path.join(__dirname, '/../test-folder'), { recursive: true, followSymlinks: false }, (err, res) => {
113113
if (isNode) {
114114
expect(err).to.not.exist
115115

0 commit comments

Comments
 (0)