Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/js-ipfs-unixfs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: [email protected]
Choose a base ref
...
head repository: ipfs/js-ipfs-unixfs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: [email protected]
Choose a head ref
  • 3 commits
  • 53 files changed
  • 3 contributors

Commits on Jul 9, 2021

  1. fix: use @ipld/dag-pb instead of ipld-dag-pb (#116)

    Swaps out the old ipld stack for the new multiformats stack.  Removes dependency on the js-ipfs API to enable easier reuse.
    
    BREAKING CHANGE: uses new multiformats stack and takes a blockservice instead of the block api
    
    Co-authored-by: Rod Vagg <[email protected]>
    Co-authored-by: achingbrain <[email protected]>
    3 people authored Jul 9, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bab1985 View commit details
  2. Copy the full SHA
    e278f54 View commit details
  3. Copy the full SHA
    dedbd82 View commit details
Showing with 807 additions and 851 deletions.
  1. +1 −0 .travis.yml
  2. +3 −1 package.json
  3. +1 −0 packages/ipfs-unixfs-exporter/.aegir.js
  4. +19 −0 packages/ipfs-unixfs-exporter/CHANGELOG.md
  5. +14 −15 packages/ipfs-unixfs-exporter/package.json
  6. +16 −16 packages/ipfs-unixfs-exporter/src/index.js
  7. +8 −6 packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js
  8. +4 −5 packages/ipfs-unixfs-exporter/src/resolvers/identity.js
  9. +13 −12 packages/ipfs-unixfs-exporter/src/resolvers/index.js
  10. +5 −5 packages/ipfs-unixfs-exporter/src/resolvers/raw.js
  11. +2 −2 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.js
  12. +31 −12 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js
  13. +14 −11 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js
  14. +1 −1 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.js
  15. +14 −12 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js
  16. +10 −9 packages/ipfs-unixfs-exporter/src/types.d.ts
  17. +26 −26 packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js
  18. +41 −49 packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js
  19. +5 −17 packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js
  20. +168 −127 packages/ipfs-unixfs-exporter/test/exporter.spec.js
  21. +4 −61 packages/ipfs-unixfs-exporter/test/helpers/block.js
  22. +13 −11 packages/ipfs-unixfs-exporter/test/helpers/collect-leaf-cids.js
  23. +11 −23 packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js
  24. +3 −15 packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js
  25. +2 −14 packages/ipfs-unixfs-exporter/test/import-export.spec.js
  26. +56 −64 packages/ipfs-unixfs-exporter/test/importer.spec.js
  27. +1 −0 packages/ipfs-unixfs-importer/.aegir.js
  28. +19 −0 packages/ipfs-unixfs-importer/CHANGELOG.md
  29. +0 −2 packages/ipfs-unixfs-importer/README.md
  30. +8 −11 packages/ipfs-unixfs-importer/package.json
  31. +4 −6 packages/ipfs-unixfs-importer/src/dag-builder/dir.js
  32. +9 −7 packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js
  33. +53 −26 packages/ipfs-unixfs-importer/src/dag-builder/file/index.js
  34. +0 −1 packages/ipfs-unixfs-importer/src/dag-builder/file/trickle.js
  35. +3 −3 packages/ipfs-unixfs-importer/src/dag-builder/index.js
  36. +15 −12 packages/ipfs-unixfs-importer/src/dir-flat.js
  37. +30 −18 packages/ipfs-unixfs-importer/src/dir-sharded.js
  38. +4 −4 packages/ipfs-unixfs-importer/src/dir.js
  39. +4 −4 packages/ipfs-unixfs-importer/src/index.js
  40. +12 −19 packages/ipfs-unixfs-importer/src/options.js
  41. +5 −5 packages/ipfs-unixfs-importer/src/tree-builder.js
  42. +25 −53 packages/ipfs-unixfs-importer/src/types.d.ts
  43. +15 −19 packages/ipfs-unixfs-importer/src/utils/persist.js
  44. +3 −16 packages/ipfs-unixfs-importer/test/benchmark.spec.js
  45. +5 −5 packages/ipfs-unixfs-importer/test/builder-balanced.spec.js
  46. +2 −13 packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js
  47. +27 −34 packages/ipfs-unixfs-importer/test/builder.spec.js
  48. +11 −16 packages/ipfs-unixfs-importer/test/chunker-custom.spec.js
  49. +1 −13 packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js
  50. +32 −46 packages/ipfs-unixfs-importer/test/helpers/block.js
  51. +8 −0 packages/ipfs-unixfs/.aegir.js
  52. +19 −0 packages/ipfs-unixfs/CHANGELOG.md
  53. +7 −4 packages/ipfs-unixfs/package.json
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
cache: npm
dist: focal

branches:
only:
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -42,10 +42,12 @@
"Bernard Mordan <bernard@tableflip.io>",
"Mithgol <getgit@mithgol.ru>",
"Irakli Gozalishvili <contact@gozala.io>",
"Arpit Agarwal <atvanguard@users.noreply.github.com>",
"Hector Sanjuan <code@hector.link>",
"Francisco Baio Dias <xicombd@gmail.com>",
"Diogo Silva <fsdiogo@gmail.com>",
"jbenet <juan@benet.ai>"
"jbenet <juan@benet.ai>",
"SahidMiller <SahidMiller@users.noreply.github.com>"
],
"workspaces": [
"packages/*"
1 change: 1 addition & 0 deletions packages/ipfs-unixfs-exporter/.aegir.js
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ const buildConfig = {
/** @type {import('aegir').PartialOptions} */
module.exports = {
build: {
bundlesizeMax: '34KB',
config: buildConfig
},
test: {
19 changes: 19 additions & 0 deletions packages/ipfs-unixfs-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [6.0.0](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-exporter@5.0.3...ipfs-unixfs-exporter@6.0.0) (2021-07-09)


### Bug Fixes

* use @ipld/dag-pb instead of ipld-dag-pb ([#116](https://github.com/ipfs/js-ipfs-unixfs/issues/116)) ([bab1985](https://github.com/ipfs/js-ipfs-unixfs/commit/bab1985e3f80c17dc94b0e9448ac993bfe78488a))


### BREAKING CHANGES

* uses new multiformats stack and takes a blockservice instead of the block api

Co-authored-by: Rod Vagg <rod@vagg.org>
Co-authored-by: achingbrain <alex@achingbrain.net>





## [5.0.3](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-exporter@5.0.2...ipfs-unixfs-exporter@5.0.3) (2021-04-20)

**Note:** Version bump only for package ipfs-unixfs-exporter
29 changes: 14 additions & 15 deletions packages/ipfs-unixfs-exporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfs-unixfs-exporter",
"version": "5.0.3",
"version": "6.0.0",
"description": "JavaScript implementation of the UnixFs exporter used by IPFS",
"leadMaintainer": "Alex Potsides <alex.potsides@protocol.ai>",
"main": "src/index.js",
@@ -12,9 +12,9 @@
"test": "aegir test",
"build": "aegir build",
"clean": "rimraf ./dist",
"lint": "aegir ts --check && aegir lint",
"lint": "aegir ts -p check && aegir lint",
"coverage": "nyc -s npm run test -t node && nyc report --reporter=html",
"depcheck": "aegir dep-check -i @types/mocha -i @types/sinon -i nyc -i abort-controller -i rimraf -i ipfs-core-types -i copy -i util -i crypto-browserify -i events -i readable-stream"
"depcheck": "aegir dep-check -i @types/mocha -i @types/sinon -i nyc -i abort-controller -i rimraf -i copy -i util -i crypto-browserify -i events -i readable-stream -i interface-blockstore"
},
"repository": {
"type": "git",
@@ -36,37 +36,36 @@
"@types/mocha": "^8.2.1",
"@types/sinon": "^10.0.0",
"abort-controller": "^3.0.0",
"aegir": "^33.1.0",
"aegir": "^34.0.0",
"copy": "^0.3.2",
"crypto-browserify": "^3.12.0",
"detect-node": "^2.0.4",
"events": "^3.3.0",
"ipfs-core-types": "^0.3.1",
"ipfs-unixfs-importer": "^7.0.3",
"ipld": "^0.29.0",
"ipld-block": "^0.11.1",
"ipld-dag-pb": "^0.22.2",
"ipld-in-memory": "^8.0.0",
"ipfs-unixfs-importer": "^8.0.0",
"it-all": "^1.0.5",
"it-buffer-stream": "^2.0.0",
"it-first": "^1.0.6",
"merge-options": "^3.0.4",
"multicodec": "^3.0.1",
"murmurhash3js-revisited": "^3.0.0",
"native-abort-controller": "^1.0.3",
"nyc": "^15.0.0",
"readable-stream": "^3.6.0",
"rimraf": "^3.0.2",
"sinon": "^10.0.0",
"sinon": "^11.1.1",
"uint8arrays": "^2.1.2",
"util": "^0.12.3"
},
"dependencies": {
"cids": "^1.1.5",
"@ipld/dag-cbor": "^6.0.4",
"@ipld/dag-pb": "^2.0.2",
"err-code": "^3.0.1",
"hamt-sharding": "^2.0.0",
"ipfs-unixfs": "^4.0.3",
"interface-blockstore": "^1.0.0",
"ipfs-unixfs": "^5.0.0",
"it-last": "^1.0.5",
"multihashing-async": "^2.1.0"
"multiformats": "^9.0.4",
"murmurhash3js-revisited": "^3.0.0",
"uint8arrays": "^2.1.5"
},
"types": "dist/src/index.d.ts",
"files": [
32 changes: 16 additions & 16 deletions packages/ipfs-unixfs-exporter/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict'

const errCode = require('err-code')
const CID = require('cids')
const { CID } = require('multiformats/cid')
const resolve = require('./resolvers')
const last = require('it-last')

/**
* @typedef {import('ipfs-unixfs').UnixFS} UnixFS
* @typedef {import('ipld-dag-pb').DAGNode} DAGNode
* @typedef {import('ipld')} IPLD
* @typedef {import('interface-blockstore').Blockstore} Blockstore
* @typedef {import('./types').ExporterOptions} ExporterOptions
* @typedef {import('./types').UnixFSFile} UnixFSFile
* @typedef {import('./types').UnixFSDirectory} UnixFSDirectory
@@ -32,14 +31,15 @@ const toPathComponents = (path = '') => {
const cidAndRest = (path) => {
if (path instanceof Uint8Array) {
return {
cid: new CID(path),
cid: CID.decode(path),
toResolve: []
}
}

if (CID.isCID(path)) {
const cid = CID.asCID(path)
if (cid) {
return {
cid: path,
cid,
toResolve: []
}
}
@@ -52,7 +52,7 @@ const cidAndRest = (path) => {
const output = toPathComponents(path)

return {
cid: new CID(output[0]),
cid: CID.parse(output[0]),
toResolve: output.slice(1)
}
}
@@ -62,10 +62,10 @@ const cidAndRest = (path) => {

/**
* @param {string | CID} path
* @param {IPLD} ipld
* @param {Blockstore} blockstore
* @param {ExporterOptions} [options]
*/
async function * walkPath (path, ipld, options = {}) {
async function * walkPath (path, blockstore, options = {}) {
let {
cid,
toResolve
@@ -75,7 +75,7 @@ async function * walkPath (path, ipld, options = {}) {
const startingDepth = toResolve.length

while (true) {
const result = await resolve(cid, name, entryPath, toResolve, startingDepth, ipld, options)
const result = await resolve(cid, name, entryPath, toResolve, startingDepth, blockstore, options)

if (!result.entry && !result.next) {
throw errCode(new Error(`Could not resolve ${path}`), 'ERR_NOT_FOUND')
@@ -99,11 +99,11 @@ async function * walkPath (path, ipld, options = {}) {

/**
* @param {string | CID} path
* @param {IPLD} ipld
* @param {Blockstore} blockstore
* @param {ExporterOptions} [options]
*/
async function exporter (path, ipld, options = {}) {
const result = await last(walkPath(path, ipld, options))
async function exporter (path, blockstore, options = {}) {
const result = await last(walkPath(path, blockstore, options))

if (!result) {
throw errCode(new Error(`Could not resolve ${path}`), 'ERR_NOT_FOUND')
@@ -114,11 +114,11 @@ async function exporter (path, ipld, options = {}) {

/**
* @param {string | CID} path
* @param {IPLD} ipld
* @param {Blockstore} blockstore
* @param {ExporterOptions} [options]
*/
async function * recursive (path, ipld, options = {}) {
const node = await exporter(path, ipld, options)
async function * recursive (path, blockstore, options = {}) {
const node = await exporter(path, blockstore, options)

if (!node) {
return
14 changes: 8 additions & 6 deletions packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const CID = require('cids')
const { CID } = require('multiformats/cid')
const errCode = require('err-code')
const dagCbor = require('@ipld/dag-cbor')

/**
* @typedef {import('../types').Resolver} Resolver
@@ -10,9 +11,9 @@ const errCode = require('err-code')
/**
* @type {Resolver}
*/
const resolve = async (cid, name, path, toResolve, resolve, depth, ipld, options) => {
const object = await ipld.get(cid, options)
const block = await ipld.get(new CID(1, 'raw', cid.multihash))
const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => {
const block = await blockstore.get(cid)
const object = dagCbor.decode(block)
let subObject = object
let subPath = path

@@ -24,7 +25,8 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, ipld, options
toResolve.shift()
subPath = `${subPath}/${prop}`

if (CID.isCID(subObject[prop])) {
const subObjectCid = CID.asCID(subObject[prop])
if (subObjectCid) {
return {
entry: {
type: 'object',
@@ -39,7 +41,7 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, ipld, options
}
},
next: {
cid: subObject[prop],
cid: subObjectCid,
name: prop,
path: subPath,
toResolve
9 changes: 4 additions & 5 deletions packages/ipfs-unixfs-exporter/src/resolvers/identity.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
const errCode = require('err-code')
const extractDataFromBlock = require('../utils/extract-data-from-block')
const validateOffsetAndLength = require('../utils/validate-offset-and-length')
const mh = require('multihashing-async').multihash
const mh = require('multiformats/hashes/digest')

/**
* @typedef {import('../types').ExporterOptions} ExporterOptions
@@ -32,12 +32,11 @@ const rawContent = (node) => {
/**
* @type {Resolver}
*/
const resolve = async (cid, name, path, toResolve, resolve, depth, ipld, options) => {
const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => {
if (toResolve.length) {
throw errCode(new Error(`No link named ${path} found in raw node ${cid}`), 'ERR_NOT_FOUND')
}

const buf = await mh.decode(cid.multihash)
const buf = await mh.decode(cid.multihash.bytes)

return {
entry: {
@@ -47,7 +46,7 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, ipld, options
cid,
content: rawContent(buf.digest),
depth,
size: buf.length,
size: buf.digest.length,
node: buf.digest
}
}
25 changes: 13 additions & 12 deletions packages/ipfs-unixfs-exporter/src/resolvers/index.js
Original file line number Diff line number Diff line change
@@ -2,11 +2,12 @@

const errCode = require('err-code')

const dagPb = require('@ipld/dag-pb')
const dagCbor = require('@ipld/dag-cbor')
const raw = require('multiformats/codecs/raw')
const { identity } = require('multiformats/hashes/identity')

/**
* @typedef {import('cids')} CID
* @typedef {import('ipld')} IPLD
* @typedef {import('../types').ExporterOptions} ExporterOptions
* @typedef {import('../types').UnixFSEntry} UnixFSEntry
* @typedef {import('../types').Resolver} Resolver
* @typedef {import('../types').Resolve} Resolve
*/
@@ -15,23 +16,23 @@ const errCode = require('err-code')
* @type {{ [ key: string ]: Resolver }}
*/
const resolvers = {
'dag-pb': require('./unixfs-v1'),
raw: require('./raw'),
'dag-cbor': require('./dag-cbor'),
identity: require('./identity')
[dagPb.code]: require('./unixfs-v1'),
[raw.code]: require('./raw'),
[dagCbor.code]: require('./dag-cbor'),
[identity.code]: require('./identity')
}

/**
* @type {Resolve}
*/
function resolve (cid, name, path, toResolve, depth, ipld, options) {
const resolver = resolvers[cid.codec]
function resolve (cid, name, path, toResolve, depth, blockstore, options) {
const resolver = resolvers[cid.code]

if (!resolver) {
throw errCode(new Error(`No resolver for codec ${cid.codec}`), 'ERR_NO_RESOLVER')
throw errCode(new Error(`No resolver for code ${cid.code}`), 'ERR_NO_RESOLVER')
}

return resolver(cid, name, path, toResolve, resolve, depth, ipld, options)
return resolver(cid, name, path, toResolve, resolve, depth, blockstore, options)
}

module.exports = resolve
10 changes: 5 additions & 5 deletions packages/ipfs-unixfs-exporter/src/resolvers/raw.js
Original file line number Diff line number Diff line change
@@ -30,23 +30,23 @@ const rawContent = (node) => {
/**
* @type {import('../types').Resolver}
*/
const resolve = async (cid, name, path, toResolve, resolve, depth, ipld, options) => {
const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => {
if (toResolve.length) {
throw errCode(new Error(`No link named ${path} found in raw node ${cid}`), 'ERR_NOT_FOUND')
}

const buf = await ipld.get(cid, options)
const block = await blockstore.get(cid, options)

return {
entry: {
type: 'raw',
name,
path,
cid,
content: rawContent(buf),
content: rawContent(block),
depth,
size: buf.length,
node: buf
size: block.length,
node: block
}
}
}
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
/**
* @type {UnixfsV1Resolver}
*/
const directoryContent = (cid, node, unixfs, path, resolve, depth, ipld) => {
const directoryContent = (cid, node, unixfs, path, resolve, depth, blockstore) => {
/**
* @param {ExporterOptions} [options]
* @returns {UnixfsV1DirectoryContent}
@@ -20,7 +20,7 @@ const directoryContent = (cid, node, unixfs, path, resolve, depth, ipld) => {
const links = node.Links.slice(offset, length)

for (const link of links) {
const result = await resolve(link.Hash, link.Name, `${path}/${link.Name}`, [], depth + 1, ipld, options)
const result = await resolve(link.Hash, link.Name || '', `${path}/${link.Name || ''}`, [], depth + 1, blockstore, options)

if (result.entry) {
yield result.entry
Loading