Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

dedupe tests #1200

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"cross-env": "^6.0.0",
"detect-node": "^2.0.4",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "~0.125.0",
"interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#fix/dedupe",
"ipfsd-ctl": "^1.0.0",
"ndjson": "^1.5.0",
"nock": "^11.4.0",
Expand Down
55 changes: 48 additions & 7 deletions src/dag/get.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const CID = require('cids')
const errCode = require('err-code')
const dagPB = require('ipld-dag-pb')
const dagCBOR = require('ipld-dag-cbor')
const raw = require('ipld-raw')
Expand All @@ -11,18 +12,58 @@ const resolvers = {
raw: raw.resolver
}

// TODO this function needs to be extracted and re-used by ipfs-http-client and ipfs
function parseArgs (cid, path, options) {
options = options || {}

// Allow options in path position
if (path !== undefined && typeof path !== 'string') {
options = path
path = undefined
}

if (typeof cid === 'string') {
if (cid.startsWith('/ipfs/')) {
cid = cid.substring(6)
}

const split = cid.split('/')

try {
cid = new CID(split[0])
} catch (err) {
throw errCode(err, 'ERR_INVALID_CID')
}

split.shift()

if (split.length > 0) {
path = split.join('/')
} else {
path = path || '/'
}
} else if (Buffer.isBuffer(cid)) {
try {
cid = new CID(cid)
} catch (err) {
throw errCode(err, 'ERR_INVALID_CID')
}
}

return [
cid,
path,
options
]
}

module.exports = config => {
const getBlock = require('../block/get')(config)
const dagResolve = require('./resolve')(config)

return configure(({ ky }) => {
return async (cid, path, options) => {
if (typeof path === 'object') {
options = path
path = null
}

options = options || {}
[cid, path, options] = parseArgs(cid, path, options)

const resolved = await dagResolve(cid, path, options)
const block = await getBlock(resolved.cid, options)
Expand Down
57 changes: 0 additions & 57 deletions test/dag.spec.js

This file was deleted.

Loading