-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use newer js-ipfs proxy libraries #288
Changes from all commits
bbacbca
0a4f59b
7e13e4f
5f40f86
6d73626
0686984
8a9bdee
b56263a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const VERSION = "0.28.2" | ||
export const VERSION = "0.29.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,5 @@ export const setup = { | |
user: "fission.name" | ||
}, | ||
|
||
shouldPin: true, | ||
shouldPin: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just remove this now, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't hurt to keep it around I guess? In case js-ipfs does turn on GC, like how it's supposed to work 😅 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
import Ipfs, { IPFS } from "ipfs-core" | ||
import Repo from "ipfs-repo" | ||
import { MemoryDatastore } from "interface-datastore" | ||
import * as fs from "fs" | ||
import * as dagPB from "@ipld/dag-pb" | ||
import * as Ipfs from "ipfs-core" | ||
|
||
import { createRepo } from "ipfs-repo" | ||
import { BlockCodec } from "multiformats/codecs/interface" | ||
import { MemoryDatastore } from "datastore-core/memory" | ||
import { MemoryBlockstore } from "blockstore-core/memory" | ||
|
||
import tempDir from "ipfs-utils/src/temp-dir.js" | ||
import type { IPFS } from "ipfs-core" | ||
|
||
|
||
export async function createInMemoryIPFS(): Promise<IPFS> { | ||
const dir = tempDir() | ||
fs.mkdirSync(dir) | ||
|
||
const memoryDs = new MemoryDatastore() | ||
const memoryBs = new MemoryBlockstore() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matheus23 Bit of double effort here, but needed to replace this to get the tests working with the new |
||
|
||
return await Ipfs.create({ | ||
offline: true, | ||
silent: true, | ||
|
@@ -14,19 +29,28 @@ export async function createInMemoryIPFS(): Promise<IPFS> { | |
Swarm: [] | ||
}, | ||
}, | ||
repo: new Repo("inmem", { | ||
lock: { | ||
lock: async () => ({ close: async () => { return } }), | ||
locked: async () => false | ||
}, | ||
autoMigrate: false, | ||
storageBackends: { | ||
root: MemoryDatastore, | ||
blocks: MemoryDatastore, | ||
keys: MemoryDatastore, | ||
datastore: MemoryDatastore, | ||
pins: MemoryDatastore, | ||
}, | ||
}) | ||
repo: createRepo( | ||
dir, | ||
codeOrName => { | ||
const lookup: Record<string, BlockCodec<number, unknown>> = { | ||
[dagPB.code]: dagPB, | ||
[dagPB.name]: dagPB | ||
} | ||
|
||
return Promise.resolve(lookup[codeOrName]) | ||
}, { | ||
root: memoryDs, | ||
blocks: memoryBs, | ||
keys: memoryDs, | ||
datastore: memoryDs, | ||
pins: memoryDs | ||
}, { | ||
repoLock: { | ||
lock: async () => ({ close: async () => { return } }), | ||
locked: async () => false | ||
}, | ||
autoMigrate: false, | ||
} | ||
) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,17 @@ | ||
import * as fs from "fs" | ||
import all from "it-all" | ||
import { IPFS } from "ipfs-core" | ||
import { CID } from "multiformats" | ||
import { CarBlockIterator } from "@ipld/car" | ||
|
||
/** | ||
* @returns the roots defined in the CAR file | ||
*/ | ||
export async function loadCAR(filepath: string, ipfs: IPFS): Promise<{ roots: CID[]; cids: CID[] }> { | ||
export async function loadCAR(filepath: string, ipfs: IPFS): Promise<{ roots: CID[] }> { | ||
const inStream = fs.createReadStream(filepath) | ||
try { | ||
const cids: CID[] = [] | ||
const blockIterator = await CarBlockIterator.fromIterable(inStream) | ||
for await (const block of blockIterator) { | ||
cids.push(block.cid) | ||
await ipfs.block.put(block.bytes, { cid: block.cid }) | ||
} | ||
return { | ||
roots: await blockIterator.getRoots(), | ||
cids, | ||
} | ||
const roots = await all(ipfs.dag.import(inStream)) | ||
return { roots: roots.map(root => root.root.cid) } | ||
} finally { | ||
inStream.close() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit dumb, but I didn't want to put too much work in here, since this is getting replaced soon anyway by WNFS v2.