This is my Datastore config:
"Datastore": {
"BloomFilterSize": 0,
"GCPeriod": "1h",
"HashOnRead": false,
"Spec": {
"mounts": [
{
"child": {
"path": "blocks",
"shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
"sync": true,
"type": "flatfs"
},
"mountpoint": "/blocks",
"prefix": "flatfs.datastore",
"type": "measure"
},
{
"child": {
"compression": "none",
"path": "datastore",
"type": "levelds"
},
"mountpoint": "/",
"prefix": "leveldb.datastore",
"type": "measure"
}
],
"type": "mount"
},
"StorageGCWatermark": 90,
"StorageMax": "10GB"
},
First question is how come blocks directory has grown to 2TB so far?
Perhaps I need to restart the daemon with
ipfs daemon --enable-gc
Or manually clean with:
ipfs repo gc
But ok, I am trying to figure out if I can use this storage as a fast cache to the files.
Then Iāve got really stuck with figuring out how can I āconvert cid to ds keyā.
Lets say I have this file:
.ipfs/blocks/DY/CIQA272DMOWSAP3RBQQJESHRQWMQM76EAHLAD2XUDXWRMFVKZLLPDYQ.data
Iāve found out that I could issue commands like:
ipfs dag resolve BCIQA272DMOWSAP3RBQQJESHRQWMQM76EAHLAD2XUDXWRMFVKZLLPDYQ
ipfs cid format BCIQA272DMOWSAP3RBQQJESHRQWMQM76EAHLAD2XUDXWRMFVKZLLPDYQ -v 0
Will give me cidv0 QmPFLZYMsVVCgdKwrLC1FxKRQcZHb6A3kNrzMuivJTWDfF
But couldnāt really find a command to do the reverse using Kubo ipfs tool.
Found some repositories like js-stores/packages/interface-datastore at main Ā· ipfs/js-stores Ā· GitHub
And an example of code to use it:
'use strict'
const base32 = require('base32.js');
import Key = require('interface-datastore').Key;
const path = require('path');
/**
* Transform a raw buffer to a base32 encoded key.
*
* @param {Buffer} rawKey
* @returns {Key}
*/
const keyFromBuffer = (rawKey) => {
const enc = new base32.Encoder();
return new Key(path.sep + enc.write(rawKey).finalize(), false);
};
/**
* Transform a raw buffer to a base32 encoded key.
*
* @param {Buffer} rawKey
* @returns {Key}
*/
const cidToDsKey = (cid) => {
return keyFromBuffer(cid.buffer);
};
But couldnāt get it to work with a little of TypeScript experience having complains about
[ERR_PACKAGE_PATH_NOT_EXPORTED]: No āexportsā main defined in ./node_modules/interface-datastore/package.json
Also, some links might be in this format:
ipfs://bafybeiao4wmudgiy32muigyaes6zs76ks5yikq56yjigaa46ksji4nhoua/11635.json
How can I convert also this ā/11635.jsonā part to get the filesystem path.
Or in this case, how do I test if the above link is present locally on the system?
I want to figure out how can I scan every block and see which cid is that and it seems to be doable with the commands I mentioned, but I would also like to have ā/11635.jsonā part from the datastore key.
And contrary from any cid link, may be just a cid in v0 or v1, or also having a sub-location like ā/11635.jsonā I want to get its local datastore key and/or a command to check if its present locally.