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

Commit 30f992b

Browse files
committed
Adds "addFiles" API.
1 parent 7835215 commit 30f992b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/api/add-files.js

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

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)