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

Commit

Permalink
Adds "addFiles" API.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed May 24, 2016
1 parent 7835215 commit 30f992b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/api/add-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const Wreck = require('wreck')
const addToDagNodesTransform = require('../add-to-dagnode-transform')

module.exports = (send) => {
return function add (path, opts, cb) {
if (typeof (opts) === 'function' && cb === undefined) {
cb = opts
opts = {}
}

if (typeof(path) !== 'string') {
return cb(new Error('"path" must be a string'))
}

var sendWithTransform = send.withTransform(addToDagNodesTransform)

return sendWithTransform('add', null, opts, path, cb)
}
}
1 change: 1 addition & 0 deletions src/load-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
function requireCommands () {
return {
add: require('./api/add'),
addFiles: require('./api/add-files'),
addUrl: require('./api/add-url'),
bitswap: require('./api/bitswap'),
block: require('./api/block'),
Expand Down
14 changes: 7 additions & 7 deletions test/api/add.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (isNode) {
}

describe('.add', () => {
it('add file', (done) => {
it('add buffer as tuple', (done) => {
if (!isNode) {
return done()
}
Expand Down Expand Up @@ -74,12 +74,12 @@ describe('.add', () => {
})
})

it('add path', (done) => {
it('local fs: add file', (done) => {
if (!isNode) {
return done()
}

apiClients.a.add(testfilePath, (err, res) => {
apiClients.a.addFiles(testfilePath, (err, res) => {
expect(err).to.not.exist

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

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

Expand All @@ -108,8 +108,8 @@ describe('.add', () => {
})
})

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

Expand Down

0 comments on commit 30f992b

Please sign in to comment.