Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 5130844

Browse files
dignifiedquiredaviddias
authored andcommitted
fix: switch to protobufjs (#39)
rm unsafe-eval
1 parent a8ff54a commit 5130844

10 files changed

+560
-64
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/dag.proto.js

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ test/repo-just-for-test*
3838

3939
# Vim .swp files
4040
**.swp
41+
42+
package-lock.json
43+
yarn.lock

.travis.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ sudo: false
22
language: node_js
33
matrix:
44
include:
5-
- node_js: 4
6-
env: CXX=g++-4.8
75
- node_js: 6
8-
env:
9-
- SAUCE=true
10-
- CXX=g++-4.8
11-
- node_js: stable
6+
env: CXX=g++-4.8
7+
- node_js: 8
128
env: CXX=g++-4.8
139

1410
# Make sure we have new NPM.
@@ -33,4 +29,4 @@ addons:
3329
sources:
3430
- ubuntu-toolchain-r-test
3531
packages:
36-
- g++-4.8
32+
- g++-4.8

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"lint": "aegir-lint",
88
"build": "aegir-build",
9+
"build-proto": "pbjs --wrap commonjs --target static-module src/dag.proto > src/dag.proto.js",
910
"test": "aegir-test",
1011
"test:node": "aegir-test node",
1112
"test:browser": "aegir-test browser",
@@ -52,7 +53,7 @@
5253
"is-ipfs": "~0.3.0",
5354
"multihashes": "~0.4.4",
5455
"multihashing-async": "~0.4.4",
55-
"protocol-buffers": "^3.2.1",
56+
"protobufjs": "^6.8.0",
5657
"pull-stream": "^3.5.0",
5758
"pull-traverse": "^1.0.3",
5859
"stable": "^0.1.6"
@@ -70,4 +71,4 @@
7071
"pre-commit": "^1.2.2",
7172
"rimraf": "^2.6.1"
7273
}
73-
}
74+
}

src/dag-node/create.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function create (data, dagLinks, hashAlg, callback) {
1414
callback = data
1515
data = undefined
1616
} else if (typeof data === 'string') {
17-
data = new Buffer(data)
17+
data = Buffer.from(data)
1818
}
1919
if (typeof dagLinks === 'function') {
2020
callback = dagLinks
@@ -26,7 +26,7 @@ function create (data, dagLinks, hashAlg, callback) {
2626
}
2727

2828
if (!Buffer.isBuffer(data)) {
29-
return callback('Passed \'data\' is not a buffer or a string!')
29+
return callback(new Error('Passed \'data\' is not a buffer or a string!'))
3030
}
3131

3232
if (!hashAlg) {

src/dag-node/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DAGNode {
1212
multihash = mh.fromB58String(multihash)
1313
}
1414

15-
this._data = data || new Buffer(0)
15+
this._data = data || Buffer.alloc(0)
1616
this._links = links || []
1717
this._serialized = serialized
1818
this._multihash = multihash

src/dag.proto

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// An IPFS MerkleDAG Link
2+
message PBLink {
3+
4+
// multihash of the target object
5+
optional bytes Hash = 1;
6+
7+
// utf string name. should be unique per object
8+
optional string Name = 2;
9+
10+
// cumulative size of target object
11+
optional uint64 Tsize = 3;
12+
}
13+
14+
// An IPFS MerkleDAG Node
15+
message PBNode {
16+
17+
// refs to other objects
18+
repeated PBLink Links = 2;
19+
20+
// opaque user data
21+
optional bytes Data = 1;
22+
}

0 commit comments

Comments
 (0)