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

Commit c6d77be

Browse files
hackergrrldaviddias
authored andcommitted
Add "addFiles" API.
1 parent 1348b45 commit c6d77be

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

src/add-to-dagnode-transform.js

Lines changed: 2 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const testfileBig = fs.readFileSync(path.join(__dirname, '/../15mb.random'))
1313
const testfile = fs.readFileSync(path.join(__dirname, '/../testfile.txt'))
1414

1515
describe('.add', () => {
16-
it('add file', (done) => {
16+
it('add buffer as tuple', (done) => {
1717
if (!isNode) {
1818
return done()
1919
}
@@ -63,7 +63,7 @@ describe('.add', () => {
6363
})
6464
})
6565

66-
it('add path', (done) => {
66+
it('local fs: add file', (done) => {
6767
if (!isNode) {
6868
return done()
6969
}
@@ -79,8 +79,8 @@ describe('.add', () => {
7979
})
8080
})
8181

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

@@ -97,8 +97,8 @@ describe('.add', () => {
9797
})
9898
})
9999

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

0 commit comments

Comments
 (0)