This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(block.rm): add block remove functionality
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
Showing
3 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} |