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

Commit 9653d67

Browse files
author
Prabhakar Poudel
committed
feat(block.rm): add block remove functionality
docs: update readme fixes #792 License: MIT Signed-off-by: Prabhakar-Poudel <[email protected]>
1 parent a04edac commit 9653d67

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

.aegir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const createServer = require('ipfsd-ctl').createServer
55
const server = createServer()
66

77
module.exports = {
8-
bundlesize: { maxSize: '236kB' },
8+
bundlesize: { maxSize: '250kB' },
99
webpack: {
1010
resolve: {
1111
mainFields: ['browser', 'main']

README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,28 @@
3434

3535
## Table of Contents
3636

37+
- [Lead Maintainer](#lead-maintainer)
38+
- [Table of Contents](#table-of-contents)
3739
- [Install](#install)
3840
- [Running the daemon with the right port](#running-the-daemon-with-the-right-port)
3941
- [Importing the module and usage](#importing-the-module-and-usage)
4042
- [Importing a sub-module and usage](#importing-a-sub-module-and-usage)
41-
- [In a web browser through Browserify](#in-a-web-browser-through-browserify)
42-
- [In a web browser from CDN](#in-a-web-browser-from-cdn)
43+
- [In a web browser](#in-a-web-browser)
4344
- [CORS](#cors)
45+
- [Custom Headers](#custom-headers)
4446
- [Usage](#usage)
45-
- [API Docs](#api)
46-
- [Callbacks and promises](#callbacks-and-promises)
47+
- [API](#api)
48+
- [Files](#files)
49+
- [Graph](#graph)
50+
- [Network](#network)
51+
- [Node Management](#node-management)
52+
- [Pubsub Caveat](#pubsub-caveat)
53+
- [Instance utils](#instance-utils)
54+
- [Static types and utils](#static-types-and-utils)
55+
- [Development](#development)
56+
- [Testing](#testing)
4757
- [Contribute](#contribute)
58+
- [Historical context](#historical-context)
4859
- [License](#license)
4960

5061
## Install
@@ -218,6 +229,7 @@ const ipfs = ipfsClient({
218229
- [block](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md)
219230
- [`ipfs.block.get(cid, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockget)
220231
- [`ipfs.block.put(block, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockput)
232+
- [`ipfs.block.rm(cids, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockrm)
221233
- [`ipfs.block.stat(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockstat)
222234

223235
- [refs](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/REFS.md)

src/block/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = (arg) => {
77

88
return {
99
get: require('./get')(send),
10-
stat: require('./stat')(send),
11-
put: require('./put')(send)
10+
put: require('./put')(send),
11+
rm: require('./rm')(send),
12+
stat: require('./stat')(send)
1213
}
1314
}

src/block/rm.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
const CID = require('cids')
5+
6+
module.exports = (send) => {
7+
return promisify((args, opts, callback) => {
8+
if (typeof opts === 'function') {
9+
callback = opts
10+
opts = {}
11+
}
12+
13+
if (!Array.isArray(args)) {
14+
args = Array(args)
15+
}
16+
17+
try {
18+
for (let i = 0; i < args.length; i++) {
19+
args[i] = new CID(args[i]).toString()
20+
}
21+
} catch (err) {
22+
return callback(err)
23+
}
24+
// args is now a valid, list of serialized (string) CID
25+
26+
const request = {
27+
path: 'block/rm',
28+
args: args,
29+
qs: opts || {}
30+
}
31+
32+
// Transform the response from { Hash, Error } objects to { hash, error } objects
33+
const transform = (stats, callback) => {
34+
callback(null, {
35+
hash: stats.Hash,
36+
error: stats.Error
37+
})
38+
}
39+
40+
send.andTransform(request, transform, callback)
41+
})
42+
}

0 commit comments

Comments
 (0)