Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat(block.rm): add block remove functionality #1026

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
42 changes: 42 additions & 0 deletions src/block/rm.js
Original file line number Diff line number Diff line change
@@ -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)
})
}