From 8d81bd40dbd51e2dee3b5a41be8079347ce75655 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 25 Jan 2018 01:20:15 +0000 Subject: [PATCH] feat: Update deps and fix tests (#20) * fix: update deps and start reviewing the code * update nodejs ver * Update readme badges * fix test --- .gitignore | 1 + .travis.yml | 2 +- README.md | 6 +++--- package.json | 11 ++++++----- src/index.js | 4 ++-- src/mfs.js | 17 +++++++++-------- tests/blob-store-test.js | 37 +++++++++++++++++-------------------- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 93f1361..8f333c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules npm-debug.log +yarn.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1bcd87c..501181f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - '4' + - '8' # Make sure we have new NPM. before_install: diff --git a/README.md b/README.md index 510d622..42fc8ed 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # ipfs-blob-store [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) -[[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) +[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) -![Build Status](https://travis-ci.org/ipfs/ipfs-blob-store.svg?style=flat-square)](https://travis-ci.org/ipfs/ipfs-blob-store) +[![Build Status](https://travis-ci.org/ipfs-shipyard/ipfs-blob-store.svg?style=flat-square)](https://travis-ci.org/ipfs-shipyard/ipfs-blob-store) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) -[![Dependency Status](https://david-dm.org/ipfs/ipfs-blob-store.svg?style=flat-square)](https://david-dm.org/ipfs/ipfs-blob-store) +[![Dependency Status](https://david-dm.org/ipfs-shipyard/ipfs-blob-store.svg?style=flat-square)](https://david-dm.org/ipfs-shipyard/ipfs-blob-store) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) > An abstract-blob-store compatible implementation built using IPFS as the storage backend diff --git a/package.json b/package.json index bdcee03..f72484f 100644 --- a/package.json +++ b/package.json @@ -28,16 +28,17 @@ }, "homepage": "https://github.com/ipfs/ipfs-blob-store", "devDependencies": { - "abstract-blob-store": "^3.2.0", - "ipfsd-ctl": "^0.16.0", - "pre-commit": "^1.1.3", - "tape": "^4.6.2" + "abstract-blob-store": "^3.3.2", + "go-ipfs-dep": "^0.4.13", + "ipfsd-ctl": "^0.27.1", + "pre-commit": "^1.2.2", + "tape": "^4.8.0" }, "pre-commit": [ "test", "lint" ], "dependencies": { - "ipfs-api": "9.0.0" + "ipfs-api": "17.5.0" } } diff --git a/src/index.js b/src/index.js index afd60b5..ff7e532 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -var ipfsAPI = require('ipfs-api') -var mfs = require('./mfs') +const ipfsAPI = require('ipfs-api') +const mfs = require('./mfs') module.exports = function (options) { if (!options) options = {} diff --git a/src/mfs.js b/src/mfs.js index dcd345b..69ccee7 100644 --- a/src/mfs.js +++ b/src/mfs.js @@ -1,4 +1,4 @@ -var stream = require('stream') +const stream = require('stream') module.exports = function (options) { var store = {} @@ -69,8 +69,12 @@ module.exports = function (options) { var passThrough = new stream.PassThrough() - ipfsCtl.files.read(store.baseDir + opts.key, {}, function (err, stream) { + ipfsCtl.files.read(store.baseDir + opts.key, {}, (err, stream) => { if (err) { + if (err.toString().indexOf('does not exist') > -1) { + err.notFound = true + } + return passThrough.emit('error', err) } @@ -85,7 +89,7 @@ module.exports = function (options) { if (opts.name) opts.key = opts.name if (!cb) cb = noop - ipfsCtl.files.stat(store.baseDir + opts.key, {}, function (err, res) { + ipfsCtl.files.stat(store.baseDir + opts.key, {}, (err, res) => { if (err) { if (err.code === 0) { return cb(null, false) @@ -102,12 +106,9 @@ module.exports = function (options) { if (opts.name) opts.key = opts.name if (!cb) cb = noop - ipfsCtl.files.rm(store.baseDir + opts.key, {}, function (err) { + ipfsCtl.files.rm(store.baseDir + opts.key, {}, (err) => { if (err) { - // console.log('error ->', err) - return cb() - // TODO files API is responding with 500 (probably cause of bitswap) - // return cb(err) + return cb(err) } cb() diff --git a/tests/blob-store-test.js b/tests/blob-store-test.js index a3e9bb6..ca76d5e 100644 --- a/tests/blob-store-test.js +++ b/tests/blob-store-test.js @@ -1,26 +1,23 @@ -var test = require('tape') -var abstractBlobTests = require('abstract-blob-store/tests') -var ipfsBlobStore = require('../src') -var ipfsd = require('ipfsd-ctl') +const test = require('tape') +const abstractBlobTests = require('abstract-blob-store/tests') +const ipfsBlobStore = require('../src') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() -ipfsd.disposable({ - apiAddr: '/ip4/127.0.0.1/tcp/13000', - init: true +df.spawn({ + disposable: true, + args: ['--api=/ip4/127.0.0.1/tcp/13000'] }, (err, node) => { if (err) { throw err } - node.startDaemon((err) => { - if (err) { - throw err - } - abstractBlobTests(test, common) - // quick hack to stop the deamon - // TODO clean up later - setTimeout(function () { - node.stopDaemon(() => {}) - }, 5000) - }) + + abstractBlobTests(test, common) + // quick hack to stop the deamon + // TODO clean up later + setTimeout(function () { + node.stop(() => {}) + }, 5000) }) var common = { @@ -31,7 +28,7 @@ var common = { } var store = ipfsBlobStore(options) - store.ipfsCtl.files.mkdir(options.baseDir, { p: true }, function (err) { + store.ipfsCtl.files.mkdir(options.baseDir, { p: true }, (err) => { if (err) { return console.error(err) } @@ -39,7 +36,7 @@ var common = { }) }, teardown: function (t, store, blob, cb) { - store.ipfsCtl.files.rm(store.baseDir, { 'recursive': true }, function (err) { + store.ipfsCtl.files.rm(store.baseDir, { recursive: true }, (err) => { if (err) { return cb(err) }