Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

feat!: rename, update, test, type, and ready for launch #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

olizilla
Copy link

Upgrade this lib so we can use it for extracting paths all over the place (dagula, freeway, etc)

  • rename to @web3-strorage/ipfs-path and the cli is now ipfs-path
  • Make extract the default cli command so it works without passing it as an arg.
  • adds linting, tsc, and fixes issues
  • adds github workflows for testing and releasing

License: MIT

Upgrade this lib so we can use it for extracting paths all over the place (dagula, freeway, etc)

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@olizilla olizilla requested a review from alanshaw April 26, 2023 10:21
License: MIT
Signed-off-by: Oli Evans <[email protected]>
Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Amazing! Feedback is all non blocking apart from the double block yield one.

cli.js Outdated
.option('-o, --output', 'Output path for CAR')
.action(async (path, car, options) => {
console.log({ path, car, options })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log({ path, car, options })

package.json Outdated
"version": "1.1.0",
"description": "Extract UnixFS paths from an existing DAG with merkle proofs.",
"description": "Extract blocks for a UnixFS paths from a DAG",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "Extract blocks for a UnixFS paths from a DAG",
"description": "Extract blocks for UnixFS paths from a DAG",

package.json Outdated
@@ -41,5 +47,12 @@
"bugs": {
"url": "https://github.com/alanshaw/ipfs-car-extract/issues"
},
"homepage": "https://github.com/alanshaw/ipfs-car-extract#readme"
"homepage": "https://github.com/alanshaw/ipfs-car-extract#readme",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"homepage": "https://github.com/alanshaw/ipfs-car-extract#readme",
"homepage": "https://github.com/web3-storage/ipfs-path#readme",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and more of these in package.json I cannot suggest for.

@@ -1,37 +1,43 @@
{
"name": "ipfs-car-extract",
"name": "@web3-storage/ipfs-path",
"version": "1.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe reset to 1.0.0?

for await (const shardBlock of findShardedBlock(node, part, blockstore)) {
if (lastBlock) yield lastBlock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is like it is because exportBlocks yields the block you pass to it, so you want to yield all the intermediate blocks here, but not the last one, otherwise you'll yield it twice.

Alternatively you could switch it round so that exportBlocks does not yield the root block you pass it, but is maybe a bigger change.

test('cli extract dagPB path', async t => {
const carName = 'extract-me.car'
const outName = 'extracted.car'
t.teardown(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I did not know this existed...

test.js Outdated
Comment on lines 39 to 52
const fsStream = Readable.from(out).pipe(fs.createWriteStream(carName))

for await (const block of readable) {
await carWriter.put(block)
}

await carWriter.close()

// wait for car to be written to fs
await new Promise((resolve, reject) => {
if (fsStream.closed) return resolve(true)
fsStream.once('finish', resolve)
fsStream.once('error', reject)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe slightly simplier with pipeline from stream/promises?:

Suggested change
const fsStream = Readable.from(out).pipe(fs.createWriteStream(carName))
for await (const block of readable) {
await carWriter.put(block)
}
await carWriter.close()
// wait for car to be written to fs
await new Promise((resolve, reject) => {
if (fsStream.closed) return resolve(true)
fsStream.once('finish', resolve)
fsStream.once('error', reject)
})
const carWritten = pipeline(out, fs.createWriteStream(carName))
for await (const block of readable) {
await carWriter.put(block)
}
await carWriter.close()
// wait for car to be written to fs
await carWritten

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! thanks!

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@@ -80,7 +77,6 @@ export function extract (blockstore, path) {
* @returns {AsyncIterable<Block>}
*/
async function * exportBlocks (blockstore, block) {
yield block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to yield the block before the recursive call to exportBlocks if not yielding from within.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants