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

Extract UnixFS paths from an existing DAG with merkle proofs.

License

Notifications You must be signed in to change notification settings

web3-storage/ipfs-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ipfs-car-extract

Extract UnixFS paths from an existing DAG with merkle proofs.

A UnixFS DAG can be large, containing multiple levels of files and directories. This tool allows you to extract a portion of a DAG by specifying the path of a file/directory. The tool will export all the blocks for the targeted file and directory as well as the intermediate blocks traversed to reach the target (the proof).

Install

npm i ipfs-car-extract

Usage

import { CarIndexedReader } from '@ipld/car/indexed-reader'
import { CarWriter } from '@ipld/car/writer'
import { extract } from 'ipfs-car-extract'
import { Readable } from 'stream'

const reader = await CarIndexedReader.fromFile('my.car')
const blocks = extract(reader, 'bafybeig5uisjbc25pkjwtyq5goocmwr7lz5ln63llrtw4d5s2y7m7nhyeu/path/to/image.png')
const { writer, out } = CarWriter.create('bafybeig5uisjbc25pkjwtyq5goocmwr7lz5ln63llrtw4d5s2y7m7nhyeu')

Readable.from(out).pipe(process.stdout)

for await (const block of blocks) {
  await writer.put(block)
}
await writer.close()

CLI

ipfs-car-extract bafybeig5uisjbc25pkjwtyq5goocmwr7lz5ln63llrtw4d5s2y7m7nhyeu/path/to/image.png my.car > image.png.car

# You can also extract a DAG that spans multiple CARs:
# ipfs-car-extract <ipfs-path> <car-file> [...car-file]

About

Extract UnixFS paths from an existing DAG with merkle proofs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published