diff --git a/.aegir.js b/.aegir.js index 1deee7d74..efd115397 100644 --- a/.aegir.js +++ b/.aegir.js @@ -5,7 +5,7 @@ const createServer = require('ipfsd-ctl').createServer const server = createServer() module.exports = { - bundlesize: { maxSize: '236kB' }, + bundlesize: { maxSize: '250kB' }, webpack: { resolve: { mainFields: ['browser', 'main'] diff --git a/README.md b/README.md index c4544e791..f45266aea 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,28 @@ ## Table of Contents +- [Lead Maintainer](#lead-maintainer) +- [Table of Contents](#table-of-contents) - [Install](#install) - [Running the daemon with the right port](#running-the-daemon-with-the-right-port) - [Importing the module and usage](#importing-the-module-and-usage) - [Importing a sub-module and usage](#importing-a-sub-module-and-usage) - - [In a web browser through Browserify](#in-a-web-browser-through-browserify) - - [In a web browser from CDN](#in-a-web-browser-from-cdn) + - [In a web browser](#in-a-web-browser) - [CORS](#cors) + - [Custom Headers](#custom-headers) - [Usage](#usage) - - [API Docs](#api) - - [Callbacks and promises](#callbacks-and-promises) + - [API](#api) + - [Files](#files) + - [Graph](#graph) + - [Network](#network) + - [Node Management](#node-management) + - [Pubsub Caveat](#pubsub-caveat) + - [Instance utils](#instance-utils) + - [Static types and utils](#static-types-and-utils) +- [Development](#development) + - [Testing](#testing) - [Contribute](#contribute) +- [Historical context](#historical-context) - [License](#license) ## Install @@ -218,6 +229,7 @@ const ipfs = ipfsClient({ - [block](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md) - [`ipfs.block.get(cid, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockget) - [`ipfs.block.put(block, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockput) + - [`ipfs.block.rm(cids, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockrm) - [`ipfs.block.stat(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockstat) - [refs](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/REFS.md) diff --git a/src/block/index.js b/src/block/index.js index f346aa454..498fbe687 100644 --- a/src/block/index.js +++ b/src/block/index.js @@ -7,7 +7,8 @@ module.exports = (arg) => { return { get: require('./get')(send), - stat: require('./stat')(send), - put: require('./put')(send) + put: require('./put')(send), + rm: require('./rm')(send), + stat: require('./stat')(send) } } diff --git a/src/block/rm.js b/src/block/rm.js new file mode 100644 index 000000000..ba77cd2c3 --- /dev/null +++ b/src/block/rm.js @@ -0,0 +1,42 @@ +'use strict' + +const promisify = require('promisify-es6') +const CID = require('cids') + +module.exports = (send) => { + return promisify((args, opts, callback) => { + if (typeof opts === 'function') { + callback = opts + opts = {} + } + + if (!Array.isArray(args)) { + args = Array(args) + } + + try { + for (let i = 0; i < args.length; i++) { + args[i] = new CID(args[i]).toString() + } + } catch (err) { + return callback(err) + } + // args is now a valid, list of serialized (string) CID + + const request = { + path: 'block/rm', + args: args, + qs: opts || {} + } + + // Transform the response from { Hash, Error } objects to { hash, error } objects + const transform = (stats, callback) => { + callback(null, { + hash: stats.Hash, + error: stats.Error + }) + } + + send.andTransform(request, transform, callback) + }) +}