New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

browser-ipfs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-ipfs - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

example/buffer.js

18

ipfs.js

@@ -0,1 +1,2 @@

(function() {
var ipfs = {};

@@ -55,3 +56,4 @@ ipfs.localProvider = {host: 'localhost', port: '5001', protocol: 'http'};

var form = new FormData();
form.append("file",new Blob([input],{}));
var data = (isBuffer(input) ? input.toString('binary') : input);
form.append("file",new Blob([data],{}));
request({

@@ -63,3 +65,3 @@ callback: callback,

accept: "application/json",
transform: function(response) { return JSON.parse(response)["Hash"]}});
transform: function(response) { return response ? JSON.parse(response)["Hash"] : null}});
};

@@ -91,2 +93,12 @@

// From https://github.com/feross/is-buffer
function isBuffer(obj) {
return !!(obj != null &&
(obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
(obj.constructor &&
typeof obj.constructor.isBuffer === 'function' &&
obj.constructor.isBuffer(obj))
))
}
if (window !== 'undefined') {

@@ -98,2 +110,2 @@ window.ipfs = ipfs;

}
})();

2

package.json
{
"name": "browser-ipfs",
"version": "0.0.2",
"version": "0.0.3",
"description": "Simplified IPFS api targeted at the browser",

@@ -5,0 +5,0 @@ "main": "ipfs.js",

@@ -7,3 +7,3 @@ # Browser friendly ipfs.js light

- no specific support for Buffers
- no specific support for Buffers. Buffer's still work, see caveat below in documentation for ipfs.cat
- only implements simple add and cat functionality

@@ -47,3 +47,3 @@ - Basically if you're using ipfs as a simple KV store, this should do the trick

#### `ipfs.add(text, callback)`
#### `ipfs.add(stringOrBuffer, callback)`

@@ -55,2 +55,11 @@ ipfs.add("Testing...", function(err, hash) {

#### `ipfs.cat(hash, callback)`
Since we want to avoid including Buffer as a specific dependency. You need to manually convert the data returned from cat to a Buffer if that is what you're expecting.
ipfs.cat("Qmc7CrwGJvRyCYZZU64aPawPj7CJ56vyBxdhxa38Dh1aKt", function(err, data) {
if (err) throw err;
console.log(new Buffer(data,'binary').toString()); // "Testing..."
});
#### `ipfs.catText(hash, callback)`

@@ -63,4 +72,6 @@

new buffer.Buffer(data, 'binary')
#### `ipfs.addJson(json, callback)`
#### `ipfs.catJson(hash, callback)`
var assert = chai.assert;
var jpgBuffer = new buffer.Buffer('ffd8ffe000104a46494600010101006000600000ffe1001645786966000049492a0008000000000000000000ffdb00430001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffdb00430101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffc00011080001000103012200021101031101ffc400150001010000000000000000000000000000000affc40014100100000000000000000000000000000000ffc40014010100000000000000000000000000000000ffc40014110100000000000000000000000000000000ffda000c03010002110311003f00bf8001ffd9', 'hex');

@@ -71,2 +72,12 @@ function log () {

});
it("add buffer to IPFS", function(done) {
ipfs.add(jpgBuffer, function(err, hash) {
ipfs.cat(hash, function(err, data) {
assert.equal(new buffer.Buffer(data,'binary').toString('hex'), jpgBuffer.toString('hex'));
done();
});
});
});
});

Sorry, the diff of this file is not supported yet

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