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

Commit

Permalink
feat(block.rm): add block remove functionality
Browse files Browse the repository at this point in the history
docs: update readme

fixes #792

License: MIT
Signed-off-by: Prabhakar-Poudel <[email protected]>
  • Loading branch information
Prabhakar Poudel committed Jun 1, 2019
1 parent a04edac commit ada8ae3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
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)
}
}
43 changes: 43 additions & 0 deletions src/block/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const promisify = require('promisify-es6')
const CID = require('cids')
const multihash = require('multihashes')

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)
})
}

0 comments on commit ada8ae3

Please sign in to comment.