src/core/components/resolve.js
// Resolve the given CID + path to a CID.
Resolve the given CID + path to a CID.
Resolve the given CID + path to a CID .
function resolve (cid, path, callback) {
    let value, remainderPath
    doUntil(
      (cb) => {
        self.block.get(cid, (err, block) => {
          if (err) return cb(err)
          const r = self._ipld.resolvers[cid.codec]
          if (!r) {
            return cb(new Error(`No resolver found for codec "${cid.codec}"`))
          }
          r.resolver.resolve(block.data, path, (err, result) => {
            if (err) return cb(err)
            value = result.value
            remainderPath = result.remainderPath
            cb()
          })
        })
      },
      () => {
        if (value && value['/']) {
          cid = new CID(value['/'])
          path = remainderPath
        } else if (CID.isCID(value)) {
          cid = value
          path = remainderPath
        } else {
          return true
        }
        return !path || path === '/'
      },
      (err) => {
        if (err) return callback(err)
        callback(null, { cid, remainderPath: path })
      }
    )
  }
function resolve ( cid , path , callback ) { let value , remainderPath doUntil ( ( cb ) => { self . block . get ( cid , ( err , block ) => { if ( err ) return cb ( err ) const r = self . _ipld . resolvers [ cid . codec ] if ( ! r ) { return cb ( new Error ( ` ${ cid . codec } ` ) ) } r . resolver . resolve ( block . data , path , ( err , result ) => { if ( err ) return cb ( err ) value = result . value remainderPath = result . remainderPath cb ( ) } ) } ) } , ( ) => { if ( value && value [ '/' ] ) { cid = new CID ( value [ '/' ] ) path = remainderPath } else if ( CID . isCID ( value ) ) { cid = value path = remainderPath } else { return true } return ! path || path === '/' } , ( err ) => { if ( err ) return callback ( err ) callback ( null , { cid , remainderPath : path } ) } ) }
Resolve the given CID + path to a CID.
Resolve the given CID + path to a CID .
// If we've hit a CID, replace the current CID. // If we've hit a CID, replace the current CID. // We've hit a value. Return the current CID and the remaining path. // Continue resolving unless the path is empty.