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: ipfs-unixfs-importer-15.2.6
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: ipfs-unixfs-importer-15.3.0
Choose a head ref
  • 4 commits
  • 24 files changed
  • 2 contributors

Commits on Sep 13, 2024

  1. chore(release): 13.5.1 [skip ci]

    ## [ipfs-unixfs-exporter-v13.5.1](ipfs-unixfs-exporter-13.5.0...ipfs-unixfs-exporter-13.5.1) (2024-09-13)
    
    ### Bug Fixes
    
    * add sideEffects false to package.json to enable tree shaking ([#402](#402)) ([aea58c4](aea58c4))
    
    ### Trivial Changes
    
    * rename master to main ([0cdfcd6](0cdfcd6))
    
    ### Dependencies
    
    * **dev:** bump aegir from 42.2.11 to 44.1.1 ([#412](#412)) ([f94d1ad](f94d1ad))
    semantic-release-bot committed Sep 13, 2024
    Copy the full SHA
    c345042 View commit details
  2. feat: add name property to errors (#414)

    Adds a `.name` property to all errors that can be used in a more
    ideomatic way than `.code`.
    achingbrain authored Sep 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    70145c7 View commit details
  3. chore(release): 11.2.0 [skip ci]

    ## [ipfs-unixfs-v11.2.0](ipfs-unixfs-11.1.5...ipfs-unixfs-11.2.0) (2024-09-13)
    
    ### Features
    
    * add name property to errors ([#414](#414)) ([70145c7](70145c7))
    semantic-release-bot committed Sep 13, 2024
    Copy the full SHA
    f55cb69 View commit details
  4. chore(release): 15.3.0 [skip ci]

    ## [ipfs-unixfs-importer-v15.3.0](ipfs-unixfs-importer-15.2.6...ipfs-unixfs-importer-15.3.0) (2024-09-13)
    
    ### Features
    
    * add name property to errors ([#414](#414)) ([70145c7](70145c7))
    semantic-release-bot committed Sep 13, 2024
    Copy the full SHA
    4d5b16f View commit details
Showing with 239 additions and 60 deletions.
  1. +14 −0 packages/ipfs-unixfs-exporter/CHANGELOG.md
  2. +1 −2 packages/ipfs-unixfs-exporter/package.json
  3. +87 −0 packages/ipfs-unixfs-exporter/src/errors.ts
  4. +6 −4 packages/ipfs-unixfs-exporter/src/index.ts
  5. +2 −2 packages/ipfs-unixfs-exporter/src/resolvers/identity.ts
  6. +2 −2 packages/ipfs-unixfs-exporter/src/resolvers/index.ts
  7. +2 −2 packages/ipfs-unixfs-exporter/src/resolvers/raw.ts
  8. +7 −7 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts
  9. +4 −4 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts
  10. +5 −5 packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts
  11. +5 −5 packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts
  12. +2 −2 packages/ipfs-unixfs-exporter/src/utils/resolve-object-path.ts
  13. +5 −5 packages/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.ts
  14. +6 −0 packages/ipfs-unixfs-importer/CHANGELOG.md
  15. +1 −2 packages/ipfs-unixfs-importer/package.json
  16. +4 −4 packages/ipfs-unixfs-importer/src/chunker/rabin.ts
  17. +3 −3 packages/ipfs-unixfs-importer/src/dag-builder/index.ts
  18. +3 −3 packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.ts
  19. +54 −0 packages/ipfs-unixfs-importer/src/errors.ts
  20. +5 −3 packages/ipfs-unixfs-importer/src/index.ts
  21. +6 −0 packages/ipfs-unixfs/CHANGELOG.md
  22. +1 −2 packages/ipfs-unixfs/package.json
  23. +10 −0 packages/ipfs-unixfs/src/errors.ts
  24. +4 −3 packages/ipfs-unixfs/src/index.ts
14 changes: 14 additions & 0 deletions packages/ipfs-unixfs-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [ipfs-unixfs-exporter-v13.5.1](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-exporter-13.5.0...ipfs-unixfs-exporter-13.5.1) (2024-09-13)

### Bug Fixes

* add sideEffects false to package.json to enable tree shaking ([#402](https://github.com/ipfs/js-ipfs-unixfs/issues/402)) ([aea58c4](https://github.com/ipfs/js-ipfs-unixfs/commit/aea58c40a4a2457ddf44454befa1eb25d4caa016))

### Trivial Changes

* rename master to main ([0cdfcd6](https://github.com/ipfs/js-ipfs-unixfs/commit/0cdfcd674513b21aab7e27b446a6f2181c9ba842))

### Dependencies

* **dev:** bump aegir from 42.2.11 to 44.1.1 ([#412](https://github.com/ipfs/js-ipfs-unixfs/issues/412)) ([f94d1ad](https://github.com/ipfs/js-ipfs-unixfs/commit/f94d1ad0a507a0b37dd601490bba22224192f5a3))

## ipfs-unixfs-exporter [13.5.0](https://github.com/ipfs/js-ipfs-unixfs/compare/ipfs-unixfs-exporter-13.4.0...ipfs-unixfs-exporter-13.5.0) (2024-02-02)


3 changes: 1 addition & 2 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": "13.5.0",
"version": "13.5.1",
"description": "JavaScript implementation of the UnixFs exporter used by IPFS",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/ipfs/js-ipfs-unixfs/tree/main/packages/ipfs-unixfs-exporter#readme",
@@ -140,7 +140,6 @@
"@ipld/dag-json": "^10.2.2",
"@ipld/dag-pb": "^4.1.2",
"@multiformats/murmur3": "^2.1.8",
"err-code": "^3.0.1",
"hamt-sharding": "^3.0.6",
"interface-blockstore": "^5.3.0",
"ipfs-unixfs": "^11.0.0",
87 changes: 87 additions & 0 deletions packages/ipfs-unixfs-exporter/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export class BadPathError extends Error {
static name = 'BadPathError'
static code = 'ERR_BAD_PATH'
name = BadPathError.name
code = BadPathError.code

constructor (message = 'Bad path') {
super(message)
}
}

export class NotFoundError extends Error {
static name = 'NotFoundError'
static code = 'ERR_NOT_FOUND'
name = NotFoundError.name
code = NotFoundError.code

constructor (message = 'Not found') {
super(message)
}
}

export class NoResolverError extends Error {
static name = 'NoResolverError'
static code = 'ERR_NO_RESOLVER'
name = NoResolverError.name
code = NoResolverError.code

constructor (message = 'No resolver') {
super(message)
}
}

export class NotUnixFSError extends Error {
static name = 'NotUnixFSError'
static code = 'ERR_NOT_UNIXFS'
name = NotUnixFSError.name
code = NotUnixFSError.code

constructor (message = 'Not UnixFS') {
super(message)
}
}

export class OverReadError extends Error {
static name = 'OverReadError'
static code = 'ERR_OVER_READ'
name = OverReadError.name
code = OverReadError.code

constructor (message = 'Over read') {
super(message)
}
}

export class UnderReadError extends Error {
static name = 'UnderReadError'
static code = 'ERR_UNDER_READ'
name = UnderReadError.name
code = UnderReadError.code

constructor (message = 'Under read') {
super(message)
}
}

export class NoPropError extends Error {
static name = 'NoPropError'
static code = 'ERR_NO_PROP'
name = NoPropError.name
code = NoPropError.code

constructor (message = 'No Property found') {
super(message)
}
}

export class InvalidParametersError extends Error {
static name = 'InvalidParametersError'
static code = 'ERR_INVALID_PARAMS'
name = InvalidParametersError.name
code = InvalidParametersError.code

constructor (message = 'Invalid parameters') {
super(message)
}
}
10 changes: 6 additions & 4 deletions packages/ipfs-unixfs-exporter/src/index.ts
Original file line number Diff line number Diff line change
@@ -45,16 +45,18 @@
* ```
*/

import errCode from 'err-code'
import last from 'it-last'
import { CID } from 'multiformats/cid'
import { BadPathError, NotFoundError } from './errors.js'
import resolve from './resolvers/index.js'
import type { PBNode } from '@ipld/dag-pb'
import type { Bucket } from 'hamt-sharding'
import type { Blockstore } from 'interface-blockstore'
import type { UnixFS } from 'ipfs-unixfs'
import type { ProgressOptions, ProgressEvent } from 'progress-events'

export * from './errors.js'

export interface ExportProgress {
/**
* How many bytes of the file have been read
@@ -361,7 +363,7 @@ const cidAndRest = (path: string | Uint8Array | CID): { cid: CID, toResolve: str
}
}

throw errCode(new Error(`Unknown path type ${path}`), 'ERR_BAD_PATH')
throw new BadPathError(`Unknown path type ${path}`)
}

/**
@@ -394,7 +396,7 @@ export async function * walkPath (path: string | CID, blockstore: ReadableStorag
const result = await resolve(cid, name, entryPath, toResolve, startingDepth, blockstore, options)

if (result.entry == null && result.next == null) {
throw errCode(new Error(`Could not resolve ${path}`), 'ERR_NOT_FOUND')
throw new NotFoundError(`Could not resolve ${path}`)
}

if (result.entry != null) {
@@ -441,7 +443,7 @@ export async function exporter (path: string | CID, blockstore: ReadableStorage,
const result = await last(walkPath(path, blockstore, options))

if (result == null) {
throw errCode(new Error(`Could not resolve ${path}`), 'ERR_NOT_FOUND')
throw new NotFoundError(`Could not resolve ${path}`)
}

return result
4 changes: 2 additions & 2 deletions packages/ipfs-unixfs-exporter/src/resolvers/identity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import errCode from 'err-code'
import * as mh from 'multiformats/hashes/digest'
import { CustomProgressEvent } from 'progress-events'
import { NotFoundError } from '../errors.js'
import extractDataFromBlock from '../utils/extract-data-from-block.js'
import validateOffsetAndLength from '../utils/validate-offset-and-length.js'
import type { ExporterOptions, Resolver, ExportProgress } from '../index.js'
@@ -28,7 +28,7 @@ const rawContent = (node: Uint8Array): ((options?: ExporterOptions) => AsyncGene

const resolve: Resolver = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => {
if (toResolve.length > 0) {
throw errCode(new Error(`No link named ${path} found in raw node ${cid}`), 'ERR_NOT_FOUND')
throw new NotFoundError(`No link named ${path} found in raw node ${cid}`)
}
const buf = mh.decode(cid.multihash.bytes)

4 changes: 2 additions & 2 deletions packages/ipfs-unixfs-exporter/src/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as dagCbor from '@ipld/dag-cbor'
import * as dagJson from '@ipld/dag-json'
import * as dagPb from '@ipld/dag-pb'
import errCode from 'err-code'
import * as json from 'multiformats/codecs/json'
import * as raw from 'multiformats/codecs/raw'
import { identity } from 'multiformats/hashes/identity'
import { NoResolverError } from '../errors.js'
import dagCborResolver from './dag-cbor.js'
import dagJsonResolver from './dag-json.js'
import identifyResolver from './identity.js'
@@ -26,7 +26,7 @@ const resolve: Resolve = async (cid, name, path, toResolve, depth, blockstore, o
const resolver = resolvers[cid.code]

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

return resolver(cid, name, path, toResolve, resolve, depth, blockstore, options)
4 changes: 2 additions & 2 deletions packages/ipfs-unixfs-exporter/src/resolvers/raw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import errCode from 'err-code'
import { CustomProgressEvent } from 'progress-events'
import { NotFoundError } from '../errors.js'
import extractDataFromBlock from '../utils/extract-data-from-block.js'
import validateOffsetAndLength from '../utils/validate-offset-and-length.js'
import type { ExporterOptions, Resolver, ExportProgress } from '../index.js'
@@ -27,7 +27,7 @@ const rawContent = (node: Uint8Array): ((options?: ExporterOptions) => AsyncGene

const resolve: Resolver = async (cid, name, path, toResolve, resolve, depth, blockstore, options) => {
if (toResolve.length > 0) {
throw errCode(new Error(`No link named ${path} found in raw node ${cid}`), 'ERR_NOT_FOUND')
throw new NotFoundError(`No link named ${path} found in raw node ${cid}`)
}

const block = await blockstore.get(cid, options)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as dagPb from '@ipld/dag-pb'
import errCode from 'err-code'
import { UnixFS } from 'ipfs-unixfs'
import map from 'it-map'
import parallel from 'it-parallel'
@@ -8,6 +7,7 @@ import { type Pushable, pushable } from 'it-pushable'
import * as raw from 'multiformats/codecs/raw'
import PQueue from 'p-queue'
import { CustomProgressEvent } from 'progress-events'
import { NotUnixFSError, OverReadError, UnderReadError } from '../../../errors.js'
import extractDataFromBlock from '../../../utils/extract-data-from-block.js'
import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js'
import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver, ReadableStorage, ExportProgress, ExportWalk } from '../../../index.js'
@@ -23,15 +23,15 @@ async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8A
}

if (node.Data == null) {
throw errCode(new Error('no data in PBNode'), 'ERR_NOT_UNIXFS')
throw new NotUnixFSError('no data in PBNode')
}

let file: UnixFS

try {
file = UnixFS.unmarshal(node.Data)
} catch (err: any) {
throw errCode(err, 'ERR_NOT_UNIXFS')
throw new NotUnixFSError(err.message)
}

// might be a unixfs `raw` node or have data on intermediate nodes
@@ -47,7 +47,7 @@ async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8A
const childOps: Array<{ link: dagPb.PBLink, blockStart: bigint }> = []

if (node.Links.length !== file.blockSizes.length) {
throw errCode(new Error('Inconsistent block sizes and dag links'), 'ERR_NOT_UNIXFS')
throw new NotUnixFSError('Inconsistent block sizes and dag links')
}

for (let i = 0; i < node.Links.length; i++) {
@@ -98,7 +98,7 @@ async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8A
child = block
break
default:
queue.end(errCode(new Error(`Unsupported codec: ${link.Hash.code}`), 'ERR_NOT_UNIXFS'))
queue.end(new NotUnixFSError(`Unsupported codec: ${link.Hash.code}`))
return
}

@@ -171,7 +171,7 @@ const fileContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth,

if (read > wanted) {
queue.end()
throw errCode(new Error('Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect'), 'ERR_OVER_READ')
throw new OverReadError('Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect')
}

if (read === wanted) {
@@ -188,7 +188,7 @@ const fileContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth,
}

if (read < wanted) {
throw errCode(new Error('Traversed entire DAG but did not read enough bytes'), 'ERR_UNDER_READ')
throw new UnderReadError('Traversed entire DAG but did not read enough bytes')
}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { decode, type PBNode } from '@ipld/dag-pb'
import errCode from 'err-code'
import { UnixFS } from 'ipfs-unixfs'
import map from 'it-map'
import parallel from 'it-parallel'
import { pipe } from 'it-pipe'
import { CustomProgressEvent } from 'progress-events'
import { NotUnixFSError } from '../../../errors.js'
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk } from '../../../index.js'

const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => {
@@ -23,18 +23,18 @@ async function * listDirectory (node: PBNode, path: string, resolve: Resolve, de
const links = node.Links

if (node.Data == null) {
throw errCode(new Error('no data in PBNode'), 'ERR_NOT_UNIXFS')
throw new NotUnixFSError('no data in PBNode')
}

let dir: UnixFS
try {
dir = UnixFS.unmarshal(node.Data)
} catch (err: any) {
throw errCode(err, 'ERR_NOT_UNIXFS')
throw new NotUnixFSError(err.message)
}

if (dir.fanout == null) {
throw errCode(new Error('missing fanout'), 'ERR_NOT_UNIXFS')
throw new NotUnixFSError('missing fanout')
}

const padLength = (dir.fanout - 1n).toString(16).length
10 changes: 5 additions & 5 deletions packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decode, type PBNode } from '@ipld/dag-pb'
import errCode from 'err-code'
import { UnixFS } from 'ipfs-unixfs'
import { NotFoundError, NotUnixFSError } from '../../errors.js'
import findShardCid from '../../utils/find-cid-in-shard.js'
import contentDirectory from './content/directory.js'
import contentFile from './content/file.js'
@@ -39,14 +39,14 @@ const unixFsResolver: Resolver = async (cid, name, path, toResolve, resolve, dep
}

if (node.Data == null) {
throw errCode(new Error('no data in PBNode'), 'ERR_NOT_UNIXFS')
throw new NotUnixFSError('no data in PBNode')
}

try {
unixfs = UnixFS.unmarshal(node.Data)
} catch (err: any) {
// non-UnixFS dag-pb node? It could happen.
throw errCode(err, 'ERR_NOT_UNIXFS')
throw new NotUnixFSError(err.message)
}

if (path == null) {
@@ -64,7 +64,7 @@ const unixFsResolver: Resolver = async (cid, name, path, toResolve, resolve, dep
}

if (linkCid == null) {
throw errCode(new Error('file does not exist'), 'ERR_NOT_FOUND')
throw new NotFoundError('file does not exist')
}

// remove the path component we have resolved
@@ -82,7 +82,7 @@ const unixFsResolver: Resolver = async (cid, name, path, toResolve, resolve, dep
const content = contentExporters[unixfs.type](cid, node, unixfs, path, resolve, depth, blockstore)

if (content == null) {
throw errCode(new Error('could not find content exporter'), 'ERR_NOT_FOUND')
throw new NotFoundError('could not find content exporter')
}

if (unixfs.isDirectory()) {
Loading