alanshaw / ipfs-only-hash

#️⃣ Just enough code to calculate the IPFS hash for some data
MIT License
135 stars 28 forks source link

How do I use this to create a V0 CID? #20

Closed MoonBoi9001 closed 2 years ago

MoonBoi9001 commented 3 years ago

It seems that the CID created is of the format V1 CID. Is it possible to instead generate a V0 CID?

MoonBoi9001 commented 3 years ago

ipfs add --only-hash --recursive

the above does exactly what I need, leaving this for someone else incase they want it

take out --recursive if you don't want the hash for every file in the directory

JulienPlanchetCoineo commented 2 years ago

Did you find a way to call recursive from the API ?

MoonBoi9001 commented 2 years ago

Did you find a way to call recursive from the API ?

Hey man yes I did, I actually found a better way that doesn't require it as well. When you upload files to ipfs inside a folder you can type the Cid of the folder into the URL and then append /X to the end to access the file inside that folder.

For example if your file is called 1.png you can do f{URL}+ "/1.png" to access it. This way you don't need to compute thousands of different CID's.

alanshaw commented 2 years ago

Yes there's a --cid-version option in the CLI:

$ ipfs-only-hash --help

  Just enough code to calculate the IPFS hash for some data

  Usage
    # get the cid v1 for the file 
    $ ipfs-only-hash <file>

    # get the cid v0 for data from stdin
    $ echo "hello world" | ipfs-only-hash --cid-version 0

$ echo "hello world" | ipfs-only-hash --cid-version 0
QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o

If you're using this programmatically I believe it outputs v0 CIDs by default but you can pass cidVersion: 0 as an option if not. Docs for that are here: https://github.com/alanshaw/ipfs-only-hash#hashofinput-options-promisestring

I'd love a PR to add directory support...or maybe fix up this one.