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

Commit

Permalink
jsipfs files add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 21, 2016
1 parent ce871a1 commit 8583416
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = function (config) {
},
externals: {
fs: '{}',
'node-forge': 'forge'
'node-forge': 'forge',
'ipfs-data-importing': '{ import: {} }'
},
node: {
Buffer: true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"hapi": "^12.0.0",
"ipfs-api": "^2.13.1",
"ipfs-blocks": "^0.1.0",
"ipfs-data-importing": "^0.3.0",
"ipfs-merkle-dag": "^0.2.1",
"ipfs-multipart": "^0.1.0",
"ipfs-repo": "^0.5.0",
Expand Down
10 changes: 0 additions & 10 deletions src/cli/commands/add.js

This file was deleted.

33 changes: 33 additions & 0 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

const Command = require('ronin').Command
const IPFS = require('../../../ipfs-core')
const debug = require('debug')
const log = debug('cli:version')
log.error = debug('cli:version:error')
const bs58 = require('bs58')

module.exports = Command.extend({
desc: 'Add a file to IPFS using the UnixFS data format',

options: {
recursive: {
alias: 'r',
type: 'boolean',
default: false
}
},

run: (recursive, path) => {
var node = new IPFS()
path = process.cwd() + '/' + path
node.files.add(path, {
recursive: recursive
}, (err, stats) => {
if (err) {
return console.log(err)
}
console.log('added', bs58.encode(stats.Hash).toString(), stats.Name)
})
}
})
2 changes: 1 addition & 1 deletion src/http-api/resources/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ exports.replace = {
}

const parser = multipart.reqParser(request.payload)
let file
var file

parser.on('file', (fileName, fileStream) => {
fileStream.on('data', (data) => {
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/resources/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ exports.put = {
}

const parser = multipart.reqParser(request.payload)
let file
var file

parser.on('file', (fileName, fileStream) => {
fileStream.on('data', (data) => {
Expand Down
9 changes: 9 additions & 0 deletions src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DAGService = mDAG.DAGService
const Id = require('peer-id')
const Info = require('peer-info')
const multiaddr = require('multiaddr')
const importer = require('ipfs-data-importing').import

exports = module.exports = IPFS

Expand Down Expand Up @@ -320,6 +321,14 @@ function IPFS (repo) {
records: {},
ping: notImpl
}

this.files = {
add: (path, options, callback) => {
options.path = path
options.dagService = dagS
importer(options, callback)
}
}
}

function notImpl () {
Expand Down

0 comments on commit 8583416

Please sign in to comment.