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

fix: added rm method for blocks #910

Closed
wants to merge 1 commit into from
Closed

fix: added rm method for blocks #910

wants to merge 1 commit into from

Conversation

sweetpalma
Copy link

@sweetpalma sweetpalma commented Dec 12, 2018

I've seen a command "ipfs block rm" in a CLI commands lists and HTTP, but seems like it is absent in js-ipfs-http-client package. I've opened this basic merge-request that adds it, but I am not sure what else should got here. Tested on my pet project, ipfs.block.rm worked like a charm.

resolves #792

@sweetpalma
Copy link
Author

As far as I can see, I need to upgrade https://github.com/ipfs/interface-ipfs-core too - I see nothing about that in the CONTRIBUTING guide. Could somebody help me with this? I really want this feature in JS client.

Copy link
Contributor

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sweetpalma thanks for the PR 🚀

Yes, we need some tests and docs for this new command in https://github.com/ipfs/interface-ipfs-core would you be willing to send a PR?

This module depends on interface-ipfs-core. You can use npm link to try out your new tests locally. See these docs to help you run only your tests while developing. This is where we import the block tests from interface-ipfs-core.

module.exports = (send) => {
return promisify((args, opts, callback) => {
if (args && CID.isCID(args)) {
args = multihash.toB58String(args.multihash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just call toString on the CID instance:

Suggested change
args = multihash.toB58String(args.multihash)
args = args.toString()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to check if args is passed as a CID in a buffer. The CID constructor will take a string/buffer/instance so it's usually best to just pass args to the constructor to nomalise the input to a CID that you can serialize. Something like this:

try {
  args = new CID(args).toString()
} catch (err) {
  return callback(err)
}
// args is now a valid, serialized (string) CID

if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a opts = opts || {} after here in case people call ipfs.block.rm(hash, null, (err) => {})

@@ -217,6 +217,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(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BLOCK.md#blockrm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method takes optional options.

@Prabhakar-Poudel
Copy link

@sweetpalma @alanshaw
This has been open for long enough. Is it okay if I take over?

@Prabhakar-Poudel
Copy link

Prabhakar-Poudel commented May 29, 2019

@alanshaw
Also the /block/rm endpoint, unlike other block/ endpoints, takes one or more multihash of blocks to remove. That implies here too we need to support multiple arguments to rm?

Read here

@alanshaw
Copy link
Contributor

alanshaw commented Nov 5, 2019

resolved in #1123

@alanshaw alanshaw closed this Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

block.rm() is missing :(
3 participants