ipfs-unixfs-exporter
Advanced tools
Comparing version
import * as dagCbor from '@ipld/dag-cbor'; | ||
import errCode from 'err-code'; | ||
import { CID } from 'multiformats/cid'; | ||
import { resolveObjectPath } from '../utils/resolve-object-path.js'; | ||
const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => { | ||
const block = await blockstore.get(cid, options); | ||
const object = dagCbor.decode(block); | ||
let subObject = object; | ||
let subPath = path; | ||
while (toResolve.length > 0) { | ||
const prop = toResolve[0]; | ||
if (prop in subObject) { | ||
// remove the bit of the path we have resolved | ||
toResolve.shift(); | ||
subPath = `${subPath}/${prop}`; | ||
const subObjectCid = CID.asCID(subObject[prop]); | ||
if (subObjectCid != null) { | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function* () { | ||
yield object; | ||
} | ||
}, | ||
next: { | ||
cid: subObjectCid, | ||
name: prop, | ||
path: subPath, | ||
toResolve | ||
} | ||
}; | ||
} | ||
subObject = subObject[prop]; | ||
} | ||
else { | ||
// cannot resolve further | ||
throw errCode(new Error(`No property named ${prop} found in cbor node ${cid}`), 'ERR_NO_PROP'); | ||
} | ||
} | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function* () { | ||
yield object; | ||
} | ||
} | ||
}; | ||
return resolveObjectPath(object, block, cid, name, path, toResolve, depth); | ||
}; | ||
export default resolve; | ||
//# sourceMappingURL=dag-cbor.js.map |
import * as dagJson from '@ipld/dag-json'; | ||
import errCode from 'err-code'; | ||
import { CID } from 'multiformats/cid'; | ||
import { resolveObjectPath } from '../utils/resolve-object-path.js'; | ||
const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => { | ||
const block = await blockstore.get(cid, options); | ||
const object = dagJson.decode(block); | ||
let subObject = object; | ||
let subPath = path; | ||
while (toResolve.length > 0) { | ||
const prop = toResolve[0]; | ||
if (prop in subObject) { | ||
// remove the bit of the path we have resolved | ||
toResolve.shift(); | ||
subPath = `${subPath}/${prop}`; | ||
const subObjectCid = CID.asCID(subObject[prop]); | ||
if (subObjectCid != null) { | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function* () { | ||
yield object; | ||
} | ||
}, | ||
next: { | ||
cid: subObjectCid, | ||
name: prop, | ||
path: subPath, | ||
toResolve | ||
} | ||
}; | ||
} | ||
subObject = subObject[prop]; | ||
} | ||
else { | ||
// cannot resolve further | ||
throw errCode(new Error(`No property named ${prop} found in dag-json node ${cid}`), 'ERR_NO_PROP'); | ||
} | ||
} | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function* () { | ||
yield object; | ||
} | ||
} | ||
}; | ||
return resolveObjectPath(object, block, cid, name, path, toResolve, depth); | ||
}; | ||
export default resolve; | ||
//# sourceMappingURL=dag-json.js.map |
@@ -5,2 +5,3 @@ import * as dagCbor from '@ipld/dag-cbor'; | ||
import errCode from 'err-code'; | ||
import * as json from 'multiformats/codecs/json'; | ||
import * as raw from 'multiformats/codecs/raw'; | ||
@@ -11,2 +12,3 @@ import { identity } from 'multiformats/hashes/identity'; | ||
import identifyResolver from './identity.js'; | ||
import jsonResolver from './json.js'; | ||
import rawResolver from './raw.js'; | ||
@@ -19,3 +21,4 @@ import dagPbResolver from './unixfs-v1/index.js'; | ||
[dagJson.code]: dagJsonResolver, | ||
[identity.code]: identifyResolver | ||
[identity.code]: identifyResolver, | ||
[json.code]: jsonResolver | ||
}; | ||
@@ -22,0 +25,0 @@ const resolve = async (cid, name, path, toResolve, depth, blockstore, options) => { |
{ | ||
"name": "ipfs-unixfs-exporter", | ||
"version": "13.4.0", | ||
"version": "13.5.0", | ||
"description": "JavaScript implementation of the UnixFs exporter used by IPFS", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
import * as dagCbor from '@ipld/dag-cbor' | ||
import errCode from 'err-code' | ||
import { CID } from 'multiformats/cid' | ||
import { resolveObjectPath } from '../utils/resolve-object-path.js' | ||
import type { Resolver } from '../index.js' | ||
@@ -9,60 +8,6 @@ | ||
const object = dagCbor.decode<any>(block) | ||
let subObject = object | ||
let subPath = path | ||
while (toResolve.length > 0) { | ||
const prop = toResolve[0] | ||
if (prop in subObject) { | ||
// remove the bit of the path we have resolved | ||
toResolve.shift() | ||
subPath = `${subPath}/${prop}` | ||
const subObjectCid = CID.asCID(subObject[prop]) | ||
if (subObjectCid != null) { | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function * () { | ||
yield object | ||
} | ||
}, | ||
next: { | ||
cid: subObjectCid, | ||
name: prop, | ||
path: subPath, | ||
toResolve | ||
} | ||
} | ||
} | ||
subObject = subObject[prop] | ||
} else { | ||
// cannot resolve further | ||
throw errCode(new Error(`No property named ${prop} found in cbor node ${cid}`), 'ERR_NO_PROP') | ||
} | ||
} | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function * () { | ||
yield object | ||
} | ||
} | ||
} | ||
return resolveObjectPath(object, block, cid, name, path, toResolve, depth) | ||
} | ||
export default resolve |
import * as dagJson from '@ipld/dag-json' | ||
import errCode from 'err-code' | ||
import { CID } from 'multiformats/cid' | ||
import { resolveObjectPath } from '../utils/resolve-object-path.js' | ||
import type { Resolver } from '../index.js' | ||
@@ -9,60 +8,6 @@ | ||
const object = dagJson.decode<any>(block) | ||
let subObject = object | ||
let subPath = path | ||
while (toResolve.length > 0) { | ||
const prop = toResolve[0] | ||
if (prop in subObject) { | ||
// remove the bit of the path we have resolved | ||
toResolve.shift() | ||
subPath = `${subPath}/${prop}` | ||
const subObjectCid = CID.asCID(subObject[prop]) | ||
if (subObjectCid != null) { | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function * () { | ||
yield object | ||
} | ||
}, | ||
next: { | ||
cid: subObjectCid, | ||
name: prop, | ||
path: subPath, | ||
toResolve | ||
} | ||
} | ||
} | ||
subObject = subObject[prop] | ||
} else { | ||
// cannot resolve further | ||
throw errCode(new Error(`No property named ${prop} found in dag-json node ${cid}`), 'ERR_NO_PROP') | ||
} | ||
} | ||
return { | ||
entry: { | ||
type: 'object', | ||
name, | ||
path, | ||
cid, | ||
node: block, | ||
depth, | ||
size: BigInt(block.length), | ||
content: async function * () { | ||
yield object | ||
} | ||
} | ||
} | ||
return resolveObjectPath(object, block, cid, name, path, toResolve, depth) | ||
} | ||
export default resolve |
@@ -5,2 +5,3 @@ import * as dagCbor from '@ipld/dag-cbor' | ||
import errCode from 'err-code' | ||
import * as json from 'multiformats/codecs/json' | ||
import * as raw from 'multiformats/codecs/raw' | ||
@@ -11,2 +12,3 @@ import { identity } from 'multiformats/hashes/identity' | ||
import identifyResolver from './identity.js' | ||
import jsonResolver from './json.js' | ||
import rawResolver from './raw.js' | ||
@@ -21,3 +23,4 @@ import dagPbResolver from './unixfs-v1/index.js' | ||
[dagJson.code]: dagJsonResolver, | ||
[identity.code]: identifyResolver | ||
[identity.code]: identifyResolver, | ||
[json.code]: jsonResolver | ||
} | ||
@@ -24,0 +27,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
259268
0.64%85
13.33%3011
-1.92%