Feature: General cli command for getting "type" info about a hash
#3430 opened on Nov 28, 2016
Description
Type: Feature
Priority: Impacts Developer Experience
Description:
It would be very useful to have a general ipfs stat <thing> command or maybe ipfs info <hash> or ipfs object type <hash> that would tell you, at the very least, what type of object the hash corresponds to (ie. blob, directory, etc.)
Example
If I do this:
$ ipfs add -w afile.txt
added <blob-hash> afile.txt
added <directory-hash>
I'd like to be able to do something like this:
$ ipfs object type <blob-hash>
blob
$ ipfs object type <directory-hash>
directory
... really I'd be happy with any means of getting ipfs to tell me the object's type. Currently the only way to figure out what type of object a hash represents is to try commands with the hash and inspect the error messages for type mis-matches.
Can't You use ipfs object stat?
It seems like ipfs object stat might provide this info but it just returns info like:
NumLinks: 1
BlockSize: 66
LinksSize: 64
DataSize: 2
CumulativeSize: 123
So you could potentially add type info into the response from this command, but currently ipfs object stat isn't returning any type info.
Why do this?
I'd like to be able to know that QmQBcXur... is a blob and QmWw4vu... is a directory because different types of objects require different commands to be useful. Given a hash, I need to know its type in order to know what commands to use in order to make sense of it:
I can run
$ ipfs cat <blob-hash>
and I can run
ipfs ls <directory-hash>
but not the other way around — I can't cat a directory object nor can I meaningfully ls a blob object.
$ ipfs cat <directory-hash>
Error: this dag node is a directory
and ipfs ls <blob-hash> doesn’t return anything at all.