-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No more fs.readFileSync and different hash functions #50
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,35 @@ | |
|
||
## Table of Contents | ||
|
||
- [Install](#install) | ||
- [Architecture](#architecture) | ||
- [Usage](#usage) | ||
- [API](#api) | ||
- [Contribute](#contribute) | ||
- [License](#license) | ||
* [Table of Contents](#table-of-contents) | ||
* [Install](#install) | ||
* [Architecture](#architecture) | ||
* [Usage](#usage) | ||
* [API](#api) | ||
+ [DAGNode Class](#dagnode-class) | ||
- [`addNodeLink`](#addnodelink) | ||
- [`addRawLink`](#addrawlink) | ||
- [`updateNodeLink`](#updatenodelink) | ||
- [`removeNodeLink`](#removenodelink) | ||
- [`removeNodeLinkByHash`](#removenodelinkbyhash) | ||
- [`copy`](#copy) | ||
- [`size`](#size) | ||
- [`links`](#links) | ||
- [`multihash(fn)`](#multihashfn) | ||
- [`marshal`](#marshal) | ||
- [`unMarshal`](#unmarshal) | ||
- [`getPBNode`](#getpbnode) | ||
- [`makeLink`](#makelink) | ||
+ [DAGLink Class](#daglink-class) | ||
+ [DAGService](#dagservice) | ||
- [`put`](#put) | ||
- [`putStream`](#putstream) | ||
- [`get`](#get) | ||
- [`getStream`](#getstream) | ||
- [`getRecursive`](#getrecursive) | ||
- [`getRecursiveStream`](#getrecursivestream) | ||
- [`remove`](#remove) | ||
* [License](#license) | ||
|
||
## Install | ||
|
||
|
@@ -99,10 +122,12 @@ var node = new ipfsMDAG.DAGNode([<data>, <[links]>]) | |
|
||
> (property) an array of `DAGLink`s belonging to the node | ||
|
||
#### `multihash` | ||
#### `multihash(fn)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't expect an actual function, just the hash identifier. Can we use a better name for this arg? Also, if there is a default. It should be |
||
|
||
> returns the multihash (default: sha2-256) | ||
|
||
`fn` can be any hash function that [`multihashing`](https://github.com/multiformats/js-multihashing) understands. | ||
|
||
#### `marshal` | ||
|
||
> returns a protobuf serialized version, compatible with go-ipfs MerkleDAG | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,12 @@ | |
|
||
const protobuf = require('protocol-buffers') | ||
const stable = require('stable') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const mh = require('multihashes') | ||
|
||
const util = require('./util') | ||
const DAGLink = require('./dag-link') | ||
|
||
const proto = protobuf(fs.readFileSync(path.join(__dirname, 'merkledag.proto'))) | ||
const proto = protobuf(require('./merkledag.proto')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new. |
||
|
||
function linkSort (a, b) { | ||
return (new Buffer(a.name || '', 'ascii').compare(new Buffer(b.name || '', 'ascii'))) | ||
|
@@ -139,8 +137,8 @@ module.exports = class DAGNode { | |
} | ||
|
||
// multihash - returns the multihash value of this DAGNode | ||
multihash () { | ||
this.encoded() | ||
multihash (fn) { | ||
this.encoded(fn) | ||
return this._cached | ||
} | ||
|
||
|
@@ -157,12 +155,17 @@ module.exports = class DAGNode { | |
|
||
// Encoded returns the encoded raw data version of a Node instance. | ||
// It may use a cached encoded version, unless the force flag is given. | ||
encoded (force) { | ||
encoded (fn, force) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is breaking API, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay will change |
||
if (typeof fn === 'boolean') { | ||
force = fn | ||
fn = undefined | ||
} | ||
|
||
if (force || !this._encoded) { | ||
this._encoded = this.marshal() | ||
|
||
if (this._encoded) { | ||
this._cached = util.hash(this._encoded) | ||
this._cached = util.hash(this._encoded, fn) | ||
} | ||
} | ||
return this._encoded | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
'use strict' | ||
|
||
module.exports = new Buffer(` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is 'ugly'.. Now I see how require worked.. this doesn't remove complexity, it even adds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It removes a lot of complexity for users, not using aegir. These proto files are the reason we need to use brfs as a preprocessor everywhere. If we drop it the code works out of the box in webpack and browserify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason for using brfs for end users today is our use of This is the first step for this :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dignifiedquire my main point is: we need to have a section in our main projects (js-ipfs, js-ipfs-api and js-libp2p) that explains our users how to 'webpack' all of this stuff, simply, it is better to have a walkthrough, even if it is obvious than having nothing. As an example, I don't believe that js-ipfs will ever stop needing a special webpack config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but we still should aim to make that explanation as simple as possible :)
I have concrete plans for this and a roadmap in my head on how to get there, it is coming soon. Dropping |
||
// An IPFS MerkleDAG Link | ||
message PBLink { | ||
|
||
|
@@ -20,3 +23,4 @@ message PBNode { | |
// opaque user data | ||
optional bytes Data = 1; | ||
} | ||
`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweeet! Thank you 👍
📜 for the 📜 god