Skip to content

Commit 940747a

Browse files
Use dignified.js
1 parent 42c29e1 commit 940747a

File tree

12 files changed

+34
-19
lines changed

12 files changed

+34
-19
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
35+
dist
36+
lib

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
"name": "ipfs-unixfs",
33
"version": "0.1.1",
44
"description": "JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)",
5-
"main": "src/index.js",
5+
"main": "lib/index.js",
6+
"jsnext:main": "src/index.js",
67
"scripts": {
7-
"test": "mocha tests/test-*.js"
8+
"test": "dignified-test",
9+
"test:node": "dignified-test node",
10+
"test:browser": "dignified-test browser",
11+
"build": "dignified-build",
12+
"lint": "dignified-lint",
13+
"release": "dignified-release"
814
},
915
"repository": {
1016
"type": "git",
@@ -21,9 +27,8 @@
2127
"homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme",
2228
"devDependencies": {
2329
"chai": "^3.5.0",
24-
"mocha": "^2.4.5",
25-
"pre-commit": "^1.1.2",
26-
"standard": "^6.0.4"
30+
"dignified.js": "github:dignifiedquire/dignified.js",
31+
"pre-commit": "^1.1.2"
2732
},
2833
"dependencies": {
2934
"protocol-buffers": "^3.1.5"
File renamed without changes.

src/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
'use strict'
2+
13
const fs = require('fs')
24
const path = require('path')
35
const protobuf = require('protocol-buffers')
4-
const schema = fs.readFileSync(path.resolve(__dirname, 'unixfs.proto'))
6+
const schema = fs.readFileSync(path.resolve(__dirname, '../protos/unixfs.proto'))
57
const pb = protobuf(schema)
6-
const unixfsData = pb.Data // encode/decode
8+
// encode/decode
9+
const unixfsData = pb.Data
710
// const unixfsMetadata = pb.MetaData // encode/decode
811

912
const types = [
@@ -14,8 +17,6 @@ const types = [
1417
'symlink'
1518
]
1619

17-
exports = module.exports = Data
18-
1920
function Data (type, data) {
2021
if (!(this instanceof Data)) {
2122
return new Data(type, data)
@@ -38,7 +39,7 @@ function Data (type, data) {
3839

3940
// data.length + blockSizes
4041
this.fileSize = () => {
41-
var sum = 0
42+
let sum = 0
4243
this.blockSizes.forEach((size) => {
4344
sum += size
4445
})
@@ -50,16 +51,18 @@ function Data (type, data) {
5051

5152
// encode to protobuf
5253
this.marshal = () => {
53-
var type
54+
let type
5455

5556
switch (this.type) {
5657
case 'raw': type = unixfsData.DataType.Raw; break
5758
case 'directory': type = unixfsData.DataType.Directory; break
5859
case 'file': type = unixfsData.DataType.File; break
5960
case 'metadata': type = unixfsData.DataType.Metadata; break
6061
case 'symlink': type = unixfsData.DataType.Symlink; break
62+
default:
63+
throw new Error(`Unkown type: "${this.type}"`)
6164
}
62-
var fileSize = this.fileSize()
65+
let fileSize = this.fileSize()
6366

6467
if (fileSize === 0) {
6568
fileSize = undefined
@@ -75,7 +78,7 @@ function Data (type, data) {
7578
}
7679

7780
// decode from protobuf https://github.com/ipfs/go-ipfs/blob/master/unixfs/format.go#L24
78-
exports.unmarshal = (marsheled) => {
81+
Data.unmarshal = (marsheled) => {
7982
const decoded = unixfsData.decode(marsheled)
8083
if (!decoded.Data) {
8184
decoded.Data = undefined
@@ -84,3 +87,5 @@ exports.unmarshal = (marsheled) => {
8487
obj.blockSizes = decoded.blocksizes
8588
return obj
8689
}
90+
91+
exports = module.exports = Data
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)