This repository was archived by the owner on Aug 12, 2020. It is now read-only.
This repository was archived by the owner on Aug 12, 2020. It is now read-only.
hash field missing in files but present for directories #189
Closed
Description
Question
Sample code - https://github.com/ipfs/js-ipfs/blob/master/src/core/components/files.js#L87
const exporter = unixfsEngine.exporter
exporter(ipfsPath, self._ipldResolver)
Following list of objects is returned.
[ { path: 'QmTyckmyosocyFaeyL8fJWQLLndx845Lx5GG3MctWfLx45',
hash: <Buffer 12 20 53 c2 b7 17 b5 86 90 a9 76 bc 7c ef a5 cd 90 4e 05 a9 ba 0d 50 35 8c 64 20 e2 db 85 2d bd f2 26> },
{ content: [Function],
path: 'QmTyckmyosocyFaeyL8fJWQLLndx845Lx5GG3MctWfLx45/Video.mp4',
size: 1114073 },
{ content: [Function],
path: 'QmTyckmyosocyFaeyL8fJWQLLndx845Lx5GG3MctWfLx45/WRAPPER_UNSUPERVISED_DIFFBOT-queries',
size: 2522 },
{ content: [Function],
path: 'QmTyckmyosocyFaeyL8fJWQLLndx845Lx5GG3MctWfLx45/cobain.png',
size: 181581 },
{ content: [Function],
path: 'QmTyckmyosocyFaeyL8fJWQLLndx845Lx5GG3MctWfLx45/cobain2.png',
size: 181581 } ]
The hash field is present only for directories (https://github.com/ipfs/js-ipfs-unixfs-engine/blob/master/src/exporter/dir-flat.js#L17) but not for files. Is this intended behaviour?
Happened to look in this code while trying to understand how js-ipfs files cat
works as part of investigation to implement js-ipfs files ls
command (ipfs/js-ipfs#927).
Adding a hash: node.multihash
here https://github.com/ipfs/js-ipfs-unixfs-engine/blob/master/src/exporter/file.js#L43 would do the trick.