src/core/components/resolve.js
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['/']) {
          // If we've hit a CID, replace the current CID.
          cid = new CID(value['/'])
          path = remainderPath
        } else if (CID.isCID(value)) {
          // If we've hit a CID, replace the current CID.
          cid = value
          path = remainderPath
        } else {
          // We've hit a value. Return the current CID and the remaining path.
          return true
        }

        // Continue resolving unless the path is empty.
        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(`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['/']) {
          // If we've hit a CID, replace the current CID.
          cid = new CID(value['/'])
          path = remainderPath
        } else if (CID.isCID(value)) {
          // If we've hit a CID, replace the current CID.
          cid = value
          path = remainderPath
        } else {
          // We've hit a value. Return the current CID and the remaining path.
          return true
        }

        // Continue resolving unless the path is empty.
        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 [ '/' ] ) { // If we've hit a CID, replace the current CID. cid = new CID ( value [ '/' ] ) path = remainderPath } else if ( CID . isCID ( value ) ) { // If we've hit a CID, replace the current CID. cid = value path = remainderPath } else { // We've hit a value. Return the current CID and the remaining path. return true } // Continue resolving unless the path is empty. 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 .