Metadata-Version: 2.1
Name: unix-fs-exporter
Version: 0.2.0
Summary: Python implementation of a ipfs unix fs exporter.
Home-page: https://github.com/kralverde/py-unix-fs-exporter/
Author: kralverde
Project-URL: Bug Tracker, https://github.com/kralverde/py-unix-fs-exporter/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.7
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: English
Classifier: Typing :: Typed
Requires-Python: >=3.7
Description-Content-Type: text/x-rst
Requires-Dist: multiformats>=0.2.1
Requires-Dist: mmh3>=4.0.1
Requires-Dist: protobuf<4,>=3.20
Requires-Dist: attrs>=23.0.0
Requires-Dist: dag-cbor>=0.3.2
Requires-Dist: hamt-sharding>=0.1.3

This code has been transpiled from `ipfs-unixfs-exporter <https://github.com/ipfs/js-ipfs-unixfs/tree/master/packages/ipfs-unixfs-exporter@88d73a6f1bb30af84ea90286145ad1b894261520>`_ and has minimal changes. 

Usage
-----

DAG-PB, Raw, DAG-CBOR, and Identity codecs are supported.

>>> from unix_fs_exporter import UnixFSFile, UnixFSDirectory, RawNode, ObjectNode, IdentityNode

Given a block store and a root cid, decode the underlying data.

>>> from unix_fs_exporter import RawNode, export, BlockStore
>>> from multiformats import CID, multicodec, multihash
...
>>> class SomeBlockStore(BlockStore):
...     def __init__(self):
...         self.mapping = dict()
...
...     async def get_block(self, cid):
...         return self.mapping[cid.digest]
...
>>> data = b'some data'
>>> mh = multihash.get('sha2-256').digest(data)
>>> cid = CID('base32', 1, 'raw', mh)
>>> block_store = SomeBlockStore()
>>> block_store.mapping[cid.digest] = data
...
>>> async def test():
...     result = await export(cid, block_store)
...     assert isinstance(result, RawNode)
...     
...     async for chunk in result.content:
...         print(chunk)
...
>>> asyncio.run(test())
b'some data'

Recursively iterate through a directory.

>>> from unix_fs_exporter import recursive_export, UnixFSFile
>>> # Creation of the blockstore is an exercise left to the reader
>>> async def test():
...     entries = recursive_export('bafybeifpaez32hlrz5tmr7scndxtjgw3auuloyuyxblynqmjw5saapewmu', block_store)
...     async for entry in entries:
...         assert isinstance(entry, UnixFSFile)
...         async for chunk in entry.content:
...             assert isinstance(chunk, bytes)
>>> asyncio.run(test())
