Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ipfs-api

Package Overview
Dependencies
Maintainers
3
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-api - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

28

examples/add.js

@@ -1,20 +0,22 @@

var ipfs = require('../')('localhost', 5001);
'use strict'
var f1 = "Hello",
f2 = "World"
var ipfs = require('../')('localhost', 5001)
ipfs.add([new Buffer(f1), new Buffer(f2)], function(err, res) {
if(err || !res) return console.log(err)
var f1 = 'Hello',
f2 = 'World'
for(var i = 0; i < res.length; i++) {
console.log(res[i])
}
ipfs.add([new Buffer(f1), new Buffer(f2)], function (err, res) {
if (err || !res) return console.log(err)
for (var i = 0; i < res.length; i++) {
console.log(res[i])
}
})
ipfs.add(["./files/hello.txt", "./files/ipfs.txt"], function(err, res) {
if(err || !res) return console.log(err)
ipfs.add(['./files/hello.txt', './files/ipfs.txt'], function (err, res) {
if (err || !res) return console.log(err)
for(var i = 0; i < res.length; i++) {
console.log(res[i])
}
for (var i = 0; i < res.length; i++) {
console.log(res[i])
}
})

@@ -1,14 +0,16 @@

var ipfs = require('../')('localhost', 5001);
'use strict'
var hash = ["QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w",
"QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu"]
var ipfs = require('../')('localhost', 5001)
ipfs.cat(hash, function(err, res) {
if(err || !res) return console.log(err)
var hash = ['QmdFyxZXsFiP4csgfM5uPu99AvFiKH62CSPDw5TP92nr7w',
'QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu']
if(res.readable) {
res.pipe(process.stdout)
} else {
console.log(res)
}
ipfs.cat(hash, function (err, res) {
if (err || !res) return console.log(err)
if (res.readable) {
res.pipe(process.stdout)
} else {
console.log(res)
}
})

@@ -1,16 +0,18 @@

var ipfs = require('../')('localhost', 5001);
'use strict'
var hash = ["QmdbHK6gMiecyjjSoPnfJg6iKMF7v6E2NkoBgGpmyCoevh"]
var ipfs = require('../')('localhost', 5001)
ipfs.ls(hash, function(err, res) {
if(err || !res) return console.log(err)
var hash = ['QmdbHK6gMiecyjjSoPnfJg6iKMF7v6E2NkoBgGpmyCoevh']
res.Objects.forEach(function(node) {
console.log(node.Hash)
ipfs.ls(hash, function (err, res) {
if (err || !res) return console.log(err)
console.log("Links [%d]", node.Links.length)
node.Links.forEach(function(link, i) {
console.log("[%d]", i, link)
})
})
res.Objects.forEach(function (node) {
console.log(node.Hash)
console.log('Links [%d]', node.Links.length)
node.Links.forEach(function (link, i) {
console.log('[%d]', i, link)
})
})
})

@@ -1,5 +0,8 @@

var ipfs = require('../')('localhost', 5001);
'use strict'
ipfs.commands(function(err, res) {
console.log(res)
var ipfs = require('../')('localhost', 5001)
ipfs.commands(function (err, res) {
if (err) throw err
console.log(res)
})

@@ -1,35 +0,38 @@

var fs = require('fs');
var http = require('http');
var Multipart = require('multipart-stream');
var qs = require('querystring');
'use strict'
var fs = require('fs')
var http = require('http')
var Multipart = require('multipart-stream')
var qs = require('querystring')
try {
var package = JSON.parse(fs.readFileSync(__dirname + '/package.json'));
var pkg = JSON.parse(fs.readFileSync(__dirname + '/package.json'))
} catch(e) {
var package = { name: 'ipfs-api-browserify', version: '?' };
var pkg = { name: 'ipfs-api-browserify', version: '?' }
}
var API_PATH = "/api/v0/";
var API_PATH = '/api/v0/'
module.exports = function(host, port) {
if(!host) host = 'localhost';
if(!port) port = 5001;
module.exports = function (host, port) {
if (!host) host = 'localhost'
if (!port) port = 5001
function send(path, args, opts, files, buffer, cb) {
if(Array.isArray(path)) path = path.join('/');
function send (path, args, opts, files, buffer, cb) {
if (Array.isArray(path)) path = path.join('/')
opts = opts || {};
if(args && !Array.isArray(args)) args = [args];
if(args) opts.arg = args;
opts['stream-channels'] = true;
var query = qs.stringify(opts);
opts = opts || {}
if (args && !Array.isArray(args)) args = [args]
if (args) opts.arg = args
opts['stream-channels'] = true
var query = qs.stringify(opts)
if(files) {
var boundary = randomString();
var contentType = 'multipart/form-data; boundary=' + boundary;
var contentType = 'application/json'
if (files) {
var boundary = randomString()
contentType = 'multipart/form-data boundary=' + boundary
}
if(typeof buffer === 'function') {
cb = buffer;
buffer = false;
if (typeof buffer === 'function') {
cb = buffer
buffer = false
}

@@ -43,69 +46,71 @@

headers: {
'User-Agent': '/node-'+package.name+'/'+package.version+'/',
'User-Agent': '/node-' + pkg.name + '/' + pkg.version + '/',
'Content-Type': contentType
},
withCredentials: false
}, function(res) {
var stream = !!res.headers['x-stream-output'];
if(stream && !buffer) return cb(null, res);
}, function (res) {
var stream = !!res.headers['x-stream-output']
if (stream && !buffer) return cb(null, res)
var chunkedObjects = !!res.headers['x-chunked-output'];
if(chunkedObjects && buffer) return cb(null, res);
var chunkedObjects = !!res.headers['x-chunked-output']
if (chunkedObjects && buffer) return cb(null, res)
var data = '';
var objects = [];
var data = ''
var objects = []
res.on('data', function(chunk) {
if(!chunkedObjects) return data += chunk;
res.on('data', function (chunk) {
if (!chunkedObjects) {
data += chunk
return data
}
try {
var obj = JSON.parse(chunk.toString());
objects.push(obj);
var obj = JSON.parse(chunk.toString())
objects.push(obj)
} catch(e) {
chunkedObjects = false;
data += chunk;
chunkedObjects = false
data += chunk
}
});
res.on('end', function() {
if(!chunkedObjects) {
})
res.on('end', function () {
if (!chunkedObjects) {
try {
var parsed = JSON.parse(data);
data = parsed;
} catch(e){}
var parsed = JSON.parse(data)
data = parsed
} catch (e) {}
} else {
data = objects;
data = objects
}
if(res.statusCode >= 400 || !res.statusCode) {
if(!data) data = new Error;
return cb(data, null);
if (res.statusCode >= 400 || !res.statusCode) {
if (!data) data = new Error()
return cb(data, null)
}
return cb(null, data);
});
res.on('error', function(err) {
return cb(err, null);
});
});
return cb(null, data)
})
res.on('error', function (err) {
return cb(err, null)
})
})
if(files) {
var stream = getFileStream(files, boundary);
stream.pipe(req);
if (files) {
var stream = getFileStream(files, boundary)
stream.pipe(req)
} else {
req.end();
req.end()
}
return req;
return req
}
function getFileStream(files, boundary) {
if(!files) return null;
function getFileStream (files, boundary) {
if (!files) return null
var mp = new Multipart(boundary);
if(!Array.isArray(files)) files = [files];
var mp = new Multipart(boundary)
if (!Array.isArray(files)) files = [files]
for(var i in files) {
var file = files[i];
for (var i in files) {
var file = files[i]
if(typeof file === 'string') {
if (typeof file === 'string') {
// TODO: get actual content type

@@ -116,7 +121,7 @@ mp.addPart({

'Content-Type': 'application/octet-stream',
'Content-Disposition': 'file; name="file"; filename="'+file+'"'
'Content-Disposition': 'file name=\'file\' filename=\'' + file + '\''
}
});
})
} else if(Buffer.isBuffer(file)) {
} else if (Buffer.isBuffer(file)) {
mp.addPart({

@@ -126,20 +131,20 @@ body: file,

'Content-Type': 'application/octet-stream',
'Content-Disposition': 'file; name="file"; filename=""'
}
});
'Content-Disposition': 'file name=\'file\' filename=\'\''
}
})
}
}
return mp;
return mp
}
function command(name) {
return function(cb) {
return send(name, null, null, null, cb);
function command (name) {
return function (cb) {
return send(name, null, null, null, cb)
}
}
function argCommand(name) {
return function(arg, cb) {
return send(name, arg, null, null, cb);
function argCommand (name) {
return function (arg, cb) {
return send(name, arg, null, null, cb)
}

@@ -151,4 +156,4 @@ }

add: function(file, cb) {
return send('add', null, null, file, cb);
add: function (file, cb) {
return send('add', null, null, file, cb)
},

@@ -160,9 +165,9 @@ cat: argCommand('cat'),

get: argCommand('config'),
set: function(key, value, cb) {
set: function (key, value, cb) {
return send('config', [key, value], null, null, cb)
},
show: function(cb) {
return send('config/show', null, null, null, true, cb);
show: function (cb) {
return send('config/show', null, null, null, true, cb)
},
replace: function(file, cb) {
replace: function (file, cb) {
return send('config/replace', null, null, file, cb)

@@ -180,14 +185,14 @@ }

mount: function(ipfs, ipns, cb) {
if(typeof ipfs === 'function') {
cb = ipfs;
ipfs = null;
} else if(typeof ipns === 'function') {
cb = ipns;
ipns = null;
mount: function (ipfs, ipns, cb) {
if (typeof ipfs === 'function') {
cb = ipfs
ipfs = null
} else if (typeof ipns === 'function') {
cb = ipns
ipns = null
}
var opts = {};
if(ipfs) opts.f = ipfs;
if(ipns) opts.n = ipns;
return send('mount', null, opts, null, cb);
var opts = {}
if (ipfs) opts.f = ipfs
if (ipns) opts.n = ipns
return send('mount', null, opts, null, cb)
},

@@ -201,7 +206,8 @@

get: argCommand('block/get'),
put: function(file, cb) {
if(Array.isArray(file))
return cb(null, new Error('block.put() only accepts 1 file'));
return send('block/put', null, null, file, cb);
},
put: function (file, cb) {
if (Array.isArray(file)) {
return cb(null, new Error('block.put() only accepts 1 file'))
}
return send('block/put', null, null, file, cb)
}
},

@@ -211,8 +217,10 @@

get: argCommand('object/get'),
put: function(file, encoding, cb) {
if(typeof encoding === 'function')
return cb(null, new Error('Must specify an object encoding ("json" or "protobuf")'))
return send('block/put', encoding, null, file, cb);
put: function (file, encoding, cb) {
if (typeof encoding === 'function') {
return cb(null, new Error('Must specify an object encoding (\'json\' or \'protobuf\')'))
}
return send('object/put', encoding, null, file, cb)
},
data: argCommand('object/data'),
stat: argCommand('object/stat'),
links: argCommand('object/links')

@@ -225,28 +233,42 @@ },

},
ping: function(id, cb) {
return send('ping', id, { n: 1 }, null, function(err, res) {
if(err) return cb(err, null);
cb(null, res[1]);
});
ping: function (id, cb) {
return send('ping', id, { n: 1 }, null, function (err, res) {
if (err) return cb(err, null)
cb(null, res[1])
})
},
id: function(id, cb) {
if(typeof id === 'function') {
cb = id;
id = null;
id: function (id, cb) {
if (typeof id === 'function') {
cb = id
id = null
}
return send('id', id, null, null, cb);
return send('id', id, null, null, cb)
},
pin: {
add: argCommand('pin/add'),
remove: argCommand('pin/rm'),
list: function(type, cb) {
if(typeof type === 'function') {
cb = type;
type = null;
add: function (hash, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = null
}
var opts = null;
if(type) opts = { type: type }
return send('pin/ls', null, opts, null, cb);
send('pin/add', hash, opts, null, cb)
},
remove: function (hash, opts, cb) {
if (typeof opts === 'function') {
cb = opts
opts = null
}
send('pin/rm', hash, opts, null, cb)
},
list: function (type, cb) {
if (typeof type === 'function') {
cb = type
type = null
}
var opts = null
if (type) opts = { type: type }
return send('pin/ls', null, opts, null, cb)
}
},

@@ -260,5 +282,13 @@

log: {
tail: function(cb) {
return send('log/tail', null, {enc: 'text'}, null, true, cb);
tail: function (cb) {
return send('log/tail', null, {enc: 'text'}, null, true, cb)
}
},
name: {
resolve: argCommand('name/resolve')
},
dht: {
findprovs: argCommand('dht/findprovs')
}

@@ -268,4 +298,4 @@ }

function randomString() {
return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2);
function randomString () {
return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)
}
{
"name": "ipfs-api",
"version": "1.1.2",
"version": "1.1.3",
"description": "A client library for the IPFS API",

@@ -9,10 +9,20 @@ "main": "index.js",

},
"repository": "ipfs/node-ipfs-api",
"repository": {
"type": "git",
"url": "https://github.com/ipfs/node-ipfs-api"
},
"contributors": [
"Travis Person <travis.person@gmail.com>"
],
"devDependencies": {},
"devDependencies": {
"standard": "^3.3.2",
"pre-commit": "^1.0.6"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "git diff --name-only --cached --relative | egrep .js$ | xargs --no-run-if-empty standard"
},
"pre-commit": [
"lint"
],
"keywords": [

@@ -22,3 +32,10 @@ "ipfs"

"author": "Matt Bell <mappum@gmail.com>",
"license": "MIT"
"license": "MIT",
"bugs": {
"url": "https://github.com/ipfs/node-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/node-ipfs-api",
"directories": {
"example": "examples"
}
}

@@ -47,3 +47,3 @@ # IPFS API via NodeJS

**Response**
```json
```
[{

@@ -150,3 +150,3 @@ Hash: string,

**Response**
```json
```
{

@@ -153,0 +153,0 @@ Links: [{

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc