How to use ipfs-repo - 7 common examples

To help you get started, we’ve selected a few ipfs-repo 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 / test / cli / version.js View on Github external
/* eslint max-nested-callbacks: ["error", 5] */
/* eslint-env mocha */
'use strict'

const os = require('os')
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const repoVersion = require('ipfs-repo').repoVersion
const pkgversion = require('../../package.json').version
const runOnAndOff = require('../utils/on-and-off')

describe('version', () => runOnAndOff((thing) => {
  let ipfs

  before(() => {
    ipfs = thing.ipfs
  })

  it('get the version', async () => {
    const out = await ipfs('version')
    expect(out).to.eql(`js-ipfs version: ${pkgversion}\n`)
  })

  it('handles --number', async () => {
github ipfs / js-ipfs / test / cli / repo.js View on Github external
/* eslint-env mocha */
'use strict'

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const repoVersion = require('ipfs-repo').repoVersion
const runOnAndOff = require('../utils/on-and-off')

describe('repo', () => runOnAndOff((thing) => {
  let ipfs

  before(() => {
    ipfs = thing.ipfs
  })

  it('get repo stats', async () => {
    const stats = await ipfs('repo stat')
    expect(stats).to.match(/^NumObjects:\s\d+$/m)
    expect(stats).to.match(/^RepoSize:\s\d+$/m)
    expect(stats).to.match(/^StorageMax:\s\d+$/m)
    expect(stats).to.match(/^RepoPath:\s.+$/m)
    expect(stats).to.match(/^Version:\s\d+$/m)
github ipfs / js-ipfs / src / core / components / repo.js View on Github external
'use strict'

const repoVersion = require('ipfs-repo').repoVersion
const callbackify = require('callbackify')

module.exports = function repo (self) {
  return {
    init: callbackify(async (bits, empty) => {
      // 1. check if repo already exists
    }),

    /**
     * If the repo has been initialized, report the current version.
     * Otherwise report the version that would be initialized.
     *
     * @param {function(Error, Number)} [callback]
     * @returns {undefined}
     */
    version: callbackify(async () => {
github ipfs / js-ipfs / src / core / boot.js View on Github external
'use strict'

const RepoErrors = require('ipfs-repo').errors

// Boot an IPFS node depending on the options set
module.exports = async (self) => {
  self.log('booting')
  const options = self._options
  const doInit = options.init
  const doStart = options.start

  // Checks if a repo exists, and if so opens it
  // Will return callback with a bool indicating the existence
  // of the repo
  async function repoOpened () {
    // nothing to do
    if (!self._repo.closed) {
      return true
    }
github ipfs / js-ipfs / src / core / boot.js View on Github external
function isRepoUninitializedError (err) {
  // If the error is that no repo exists,
  // which happens when the version file is not found
  // we just want to signal that no repo exist, not
  // fail the whole process.

  // Use standardized errors as much as possible
  if (err.code === RepoErrors.ERR_REPO_NOT_INITIALIZED) {
    return true
  }

  // TODO: As error codes continue to be standardized, this logic can be phase out;
  // it is here to maintain compatibility
  if (err.message.match(/not found/) || // indexeddb
    err.message.match(/ENOENT/) || // fs
    err.message.match(/No value/) // memory
  ) {
    return true
  }

  return false
}
github ipfs / js-ipfs / src / core / components-ipfsx / init.js View on Github external
const NoKeychain = require('../components/no-keychain')
const GCLock = require('../components/pin/gc-lock')
const { DAGNode } = require('ipld-dag-pb')
const UnixFs = require('ipfs-unixfs')
const multicodec = require('multicodec')
const multiaddr = require('multiaddr')
const {
  AlreadyInitializingError,
  AlreadyInitializedError,
  NotStartedError
} = require('../../errors')
const BlockService = require('ipfs-block-service')
const Ipld = require('ipld')
const getDefaultIpldOptions = require('../runtime/ipld-nodejs')
const createPreloader = require('./preload')
const { ERR_REPO_NOT_INITIALIZED } = require('ipfs-repo').errors
const IPNS = require('../ipns')
const OfflineDatastore = require('../ipns/routing/offline-datastore')
const initAssets = require('../runtime/init-assets-nodejs')
const Components = require('.')
const PinManager = require('../components/pin/pin-manager')

module.exports = ({
  apiManager,
  print,
  constructorOptions
}) => async function init (options) {
  const { cancel } = apiManager.update({ init: () => { throw new AlreadyInitializingError() } })

  try {
    options = mergeOptions({}, options, constructorOptions.init)
github ipfs / js-ipfs / src / core / components / repo / gc.js View on Github external
const removeBlock = async ({ key: k }) => {
    blocksCount++

    try {
      const cid = Repo.utils.blockstore.keyToCid(k)
      const b32 = cid.toV1().toString('base32')
      if (markedSet.has(b32)) return null
      const res = { cid }

      try {
        await repo.blocks.delete(cid)
        removedBlocksCount++
      } catch (err) {
        res.err = new Error(`Could not delete block with CID ${cid}: ${err.message}`)
      }

      return res
    } catch (err) {
      const msg = `Could not convert block with key '${k}' to CID`
      log(msg, err)
      return { err: new Error(msg + `: ${err.message}`) }

ipfs-repo

IPFS Repo implementation

Apache-2.0 OR MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis