Skip to content

Commit b332b16

Browse files
authored
fix: use simpler blockstore interface (#287)
Instead of expecting a full `interface-blockstore` implementation, only use a subset of the methods.
1 parent 8446b1d commit b332b16

File tree

13 files changed

+29
-34
lines changed

13 files changed

+29
-34
lines changed

packages/ipfs-unixfs-exporter/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"build": "aegir build",
132132
"clean": "aegir clean",
133133
"lint": "aegir lint",
134-
"dep-check": "aegir dep-check -i interface-blockstore",
134+
"dep-check": "aegir dep-check",
135135
"release": "aegir release"
136136
},
137137
"dependencies": {
@@ -140,7 +140,7 @@
140140
"@multiformats/murmur3": "^2.0.0",
141141
"err-code": "^3.0.1",
142142
"hamt-sharding": "^3.0.0",
143-
"interface-blockstore": "^4.0.0",
143+
"interface-blockstore": "^4.0.1",
144144
"ipfs-unixfs": "^11.0.0",
145145
"it-filter": "^2.0.0",
146146
"it-last": "^2.0.0",

packages/ipfs-unixfs-exporter/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import resolve from './resolvers/index.js'
44
import last from 'it-last'
55
import type { UnixFS } from 'ipfs-unixfs'
66
import type { PBNode } from '@ipld/dag-pb'
7-
import type { Blockstore } from 'interface-blockstore'
7+
import type { Blockstore as InterfaceBlockstore } from 'interface-blockstore'
88
import type { Bucket } from 'hamt-sharding'
99

1010
export interface ExporterOptions {
@@ -79,6 +79,12 @@ export interface ShardTraversalContext {
7979
lastBucket: Bucket<boolean>
8080
}
8181

82+
export interface BlockstoreOptions {
83+
signal?: AbortSignal
84+
}
85+
86+
export type Blockstore = Pick<InterfaceBlockstore, 'has' | 'put' | 'get'>
87+
8288
const toPathComponents = (path: string = ''): string[] => {
8389
// split on / unless escaped with \
8490
return (path

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import parallel from 'it-parallel'
99
import { pipe } from 'it-pipe'
1010
import map from 'it-map'
1111
import PQueue from 'p-queue'
12-
import type { Blockstore } from 'interface-blockstore'
13-
import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver } from '../../../index.js'
12+
import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver, Blockstore } from '../../../index.js'
1413

1514
async function walkDAG (blockstore: Blockstore, node: dagPb.PBNode | Uint8Array, queue: Pushable<Uint8Array>, streamPosition: bigint, start: bigint, end: bigint, walkQueue: PQueue, options: ExporterOptions): Promise<void> {
1615
// a `raw` node

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@ import parallel from 'it-parallel'
22
import { pipe } from 'it-pipe'
33
import map from 'it-map'
44
import { decode, PBNode } from '@ipld/dag-pb'
5-
import type { Blockstore } from 'interface-blockstore'
6-
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver } from '../../../index.js'
7-
8-
/**
9-
* @typedef {import('interface-blockstore').Blockstore} Blockstore
10-
* @typedef {import('../../../types').ExporterOptions} ExporterOptions
11-
* @typedef {import('../../../types').Resolve} Resolve
12-
* @typedef {import('../../../types').UnixfsV1DirectoryContent} UnixfsV1DirectoryContent
13-
* @typedef {import('../../../types').UnixfsV1Resolver} UnixfsV1Resolver
14-
* @typedef {import('@ipld/dag-pb').PBNode} PBNode
15-
*/
5+
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, Blockstore } from '../../../index.js'
166

177
const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => {
188
function yieldHamtDirectoryContent (options: ExporterOptions = {}): UnixfsV1DirectoryContent {

packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import { Bucket, BucketPosition, createHAMT } from 'hamt-sharding'
33
import { decode, PBLink, PBNode } from '@ipld/dag-pb'
44
import { murmur3128 } from '@multiformats/murmur3'
5-
import type { Blockstore } from 'interface-blockstore'
6-
import type { ExporterOptions, ShardTraversalContext } from '../index.js'
5+
import type { ExporterOptions, ShardTraversalContext, Blockstore } from '../index.js'
76
import type { CID } from 'multiformats/cid'
87

98
// FIXME: this is copy/pasted from ipfs-unixfs-importer/src/options.js

packages/ipfs-unixfs-importer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,16 @@
155155
"build": "aegir build",
156156
"clean": "aegir clean",
157157
"lint": "aegir lint",
158-
"dep-check": "aegir dep-check -i interface-blockstore",
158+
"dep-check": "aegir dep-check",
159159
"release": "aegir release"
160160
},
161161
"dependencies": {
162162
"@ipld/dag-pb": "^4.0.0",
163163
"@multiformats/murmur3": "^2.0.0",
164164
"err-code": "^3.0.1",
165165
"hamt-sharding": "^3.0.0",
166-
"interface-blockstore": "^4.0.0",
167166
"ipfs-unixfs": "^11.0.0",
167+
"interface-blockstore": "^4.0.1",
168168
"it-all": "^2.0.0",
169169
"it-batch": "^2.0.0",
170170
"it-first": "^2.0.0",

packages/ipfs-unixfs-importer/src/dag-builder/dir.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { UnixFS } from 'ipfs-unixfs'
22
import { persist } from '../utils/persist.js'
33
import { encode, prepare } from '@ipld/dag-pb'
4-
import type { Directory, InProgressImportResult } from '../index.js'
5-
import type { Blockstore } from 'interface-blockstore'
4+
import type { Directory, InProgressImportResult, Blockstore } from '../index.js'
65
import type { Version } from 'multiformats/cid'
76

87
export interface DirBuilderOptions {

packages/ipfs-unixfs-importer/src/dag-builder/file.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { persist } from '../utils/persist.js'
33
import { encode, PBLink, prepare } from '@ipld/dag-pb'
44
import parallelBatch from 'it-parallel-batch'
55
import * as rawCodec from 'multiformats/codecs/raw'
6-
import type { BufferImporter, File, InProgressImportResult } from '../index.js'
7-
import type { Blockstore } from 'interface-blockstore'
6+
import type { BufferImporter, File, InProgressImportResult, Blockstore } from '../index.js'
87
import type { FileLayout, Reducer } from '../layout/index.js'
98
import type { Version } from 'multiformats/cid'
109

@@ -49,9 +48,9 @@ const reduce = (file: File, blockstore: Blockstore, options: ReduceOptions): Red
4948
const leaf = leaves[0]
5049

5150
if (file.mtime !== undefined || file.mode !== undefined) {
52-
// only one leaf node which is a buffer - we have metadata so convert it into a
51+
// only one leaf node which is a raw leaf - we have metadata so convert it into a
5352
// UnixFS entry otherwise we'll have nowhere to store the metadata
54-
let buffer = await blockstore.get(leaf.cid)
53+
let buffer = await blockstore.get(leaf.cid, options)
5554

5655
leaf.unixfs = new UnixFS({
5756
type: 'file',

packages/ipfs-unixfs-importer/src/dag-builder/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { dirBuilder, DirBuilderOptions } from './dir.js'
22
import { fileBuilder, FileBuilderOptions } from './file.js'
33
import errCode from 'err-code'
4-
import type { Directory, File, FileCandidate, ImportCandidate, InProgressImportResult } from '../index.js'
5-
import type { Blockstore } from 'interface-blockstore'
4+
import type { Directory, File, FileCandidate, ImportCandidate, InProgressImportResult, Blockstore } from '../index.js'
65
import type { ChunkValidator } from './validate-chunks.js'
76
import type { Chunker } from '../chunker/index.js'
87

packages/ipfs-unixfs-importer/src/dir.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { Blockstore } from 'interface-blockstore'
1+
import type { Blockstore, ImportResult, InProgressImportResult } from './index.js'
22
import type { Mtime, UnixFS } from 'ipfs-unixfs'
33
import { CID } from 'multiformats/cid'
4-
import type { ImportResult, InProgressImportResult } from './index.js'
54
import type { PersistOptions } from './utils/persist.js'
65

76
export interface DirProps {

packages/ipfs-unixfs-importer/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DAGBuilder, defaultDagBuilder } from './dag-builder/index.js'
33
import { defaultTreeBuilder } from './tree-builder.js'
44
import type { UnixFS, Mtime } from 'ipfs-unixfs'
55
import type { CID, Version as CIDVersion } from 'multiformats/cid'
6-
import type { Blockstore } from 'interface-blockstore'
6+
import type { Blockstore as InterfaceBlockstore } from 'interface-blockstore'
77
import { ChunkValidator, defaultChunkValidator } from './dag-builder/validate-chunks.js'
88
import { fixedSize } from './chunker/fixed-size.js'
99
import type { Chunker } from './chunker/index.js'
@@ -16,6 +16,12 @@ import type { AwaitIterable } from 'blockstore-core/base'
1616
export type ByteStream = AwaitIterable<Uint8Array>
1717
export type ImportContent = ByteStream | Uint8Array
1818

19+
export interface BlockstoreOptions {
20+
signal?: AbortSignal
21+
}
22+
23+
export type Blockstore = Pick<InterfaceBlockstore, 'has' | 'put' | 'get'>
24+
1925
export interface FileCandidate {
2026
path?: string
2127
content: ImportContent

packages/ipfs-unixfs-importer/src/tree-builder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { DirFlat } from './dir-flat.js'
22
import { flatToShard } from './flat-to-shard.js'
33
import { Dir } from './dir.js'
44
import { toPathComponents } from './utils/to-path-components.js'
5-
import type { ImportResult, InProgressImportResult, TreeBuilder } from './index.js'
6-
import type { Blockstore } from 'interface-blockstore'
5+
import type { ImportResult, InProgressImportResult, TreeBuilder, Blockstore } from './index.js'
76
import type { PersistOptions } from './utils/persist.js'
87

98
export interface AddToTreeOptions extends PersistOptions {

packages/ipfs-unixfs-importer/src/utils/persist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CID } from 'multiformats/cid'
22
import * as dagPb from '@ipld/dag-pb'
33
import { sha256 } from 'multiformats/hashes/sha2'
4-
import type { Blockstore } from 'interface-blockstore'
4+
import type { Blockstore } from '../index.js'
55
import type { BlockCodec } from 'multiformats/codecs/interface'
66
import type { Version as CIDVersion } from 'multiformats/cid'
77

0 commit comments

Comments
 (0)