How to use the is-ipfs.ipfsPath function in is-ipfs

To help you get started, we’ve selected a few is-ipfs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / js-ipfs-http-client / src / files-regular / get-pull-stream.js View on Github external
return (path, opts) => {
    opts = opts || {}

    const p = deferred.source()

    try {
      path = cleanCID(path)
    } catch (err) {
      if (!v.ipfsPath(path)) {
        return p.end(err)
      }
    }

    const request = { path: 'get', args: path, qs: opts }

    // Convert the response stream to TarStream objects
    send.andTransform(request, TarStreamToObjects, (err, stream) => {
      if (err) { return p.end(err) }

      p.resolve(
        pull(
          toPull.source(stream),
          map(file => {
            const { path, content } = file
            return content ? { path, content: toPull.source(content) } : file
github pathephone / pathephone-desktop / app / api / ipfs / src / files / get.js View on Github external
callback = opts
      opts = {}
    }

    // opts is the real callback --
    // 'callback' is being injected by promisify
    if (typeof opts === 'function' &&
        typeof callback === 'function') {
      callback = opts
      opts = {}
    }

    try {
      path = cleanCID(path)
    } catch (err) {
      if (!v.ipfsPath(path)) {
        return callback(err)
      }
    }

    const request = {
      path: 'get',
      args: path,
      qs: opts
    }

    // Convert the response stream to TarStream objects
    send.andTransform(request, TarStreamToObjects, callback)
  })
}
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-proxy / pre-mfs-scope.js View on Github external
function safePathPrefix (prefix, path, isDestination) {
  const realPath = safePath(path)
  if (!isDestination && IsIpfs.ipfsPath(realPath)) {
    // we don't prefix valid /ipfs/ paths in source paths
    // (those are public and immutable, so safe as-is)
    return realPath
  }
  return Path.join(prefix, realPath)
}
github ipfs / js-ipfs / src / http / api / resources / files-regular.js View on Github external
exports.parseKey = (request, h) => {
  const { arg } = request.query

  if (!arg) {
    throw Boom.badRequest("Argument 'key' is required")
  }

  const isArray = Array.isArray(arg)
  const args = isArray ? arg : [arg]
  for (const arg of args) {
    if (!isIpfs.ipfsPath(arg) && !isIpfs.cid(arg) && !isIpfs.ipfsPath('/ipfs/' + arg)) {
      throw Boom.badRequest(`invalid ipfs ref path '${arg}'`)
    }
  }

  return {
    key: isArray ? args : arg,
    options: {
      offset: numberFromQuery(request.query, 'offset'),
      length: numberFromQuery(request.query, 'length')
    }
  }
}
github ipfs / js-ipfs / src / core / components / files-mfs.js View on Github external
    const paths = args.filter(arg => isIpfs.ipfsPath(arg) || isIpfs.cid(arg))
github ipfs / js-ipfs-http-client / src / files-regular / cat-pull-stream.js View on Github external
return (hash, opts) => {
    opts = opts || {}

    const p = deferred.source()

    try {
      hash = cleanCID(hash)
    } catch (err) {
      if (!v.ipfsPath(hash)) {
        return p.end(err)
      }
    }

    const query = {
      offset: opts.offset,
      length: opts.length
    }

    send({ path: 'cat', args: hash, buffer: opts.buffer, qs: query }, (err, stream) => {
      if (err) { return p.end(err) }

      p.resolve(toPull(stream))
    })

    return p
github ipfs-shipyard / ipfs-desktop / src / controls / utils.js View on Github external
export function validateIPFS (text) {
  return isIPFS.multihash(text) ||
    isIPFS.cid(text) ||
    isIPFS.ipfsPath(text) ||
    isIPFS.ipfsPath(`/ipfs/${text}`)
}
github ipfs-shipyard / ipfs-desktop / src / controls / utils.js View on Github external
export function validateIPFS (text) {
  return isIPFS.multihash(text) ||
    isIPFS.cid(text) ||
    isIPFS.ipfsPath(text) ||
    isIPFS.ipfsPath(`/ipfs/${text}`)
}
github ipfs / js-ipfs-http-client / src / files-regular / cat-readable-stream.js View on Github external
return (hash, opts) => {
    opts = opts || {}

    const pt = new Stream.PassThrough()

    try {
      hash = cleanCID(hash)
    } catch (err) {
      if (!v.ipfsPath(hash)) {
        return pt.destroy(err)
      }
    }

    const query = {
      offset: opts.offset,
      length: opts.length
    }

    send({ path: 'cat', args: hash, buffer: opts.buffer, qs: query }, (err, stream) => {
      if (err) { return pt.destroy(err) }

      pump(stream, pt)
    })

    return pt

is-ipfs

A set of utilities to help identify IPFS resources on the web

Apache-2.0 OR MIT
Latest version published 10 months ago

Package Health Score

64 / 100
Full package analysis