Skip to main content

Pure python implementation of a ipfs CAR block decoder.

Project description

Validate what an IPFS gateway returns by decoding and validating the CAR block.

Usage

CARs can be read from memory or file and can be exported as a file/folder or byte stream

>>> import asyncio
>>> import aiohttp
...
>>> from ipfs_car_decoder import ChunkedMemoryByteStream, stream_bytes
...
>>> ipfs_hash = 'bafkreibm6jg3ux5qumhcn2b3flc3tyu6dmlb4xa7u5bf44yegnrjhc4yeq'
...
>>> async def test():
...     stream = ChunkedMemoryByteStream()
...     async with aiohttp.ClientSession() as session:
...         async with session.get(f'https://ipfs.io/ipfs/{ipfs_hash}', headers={'Accept':'application/vnd.ipld.car'}) as resp:
...             resp.raise_for_status()
...             assert resp.content_type == 'application/vnd.ipld.car'
...             async for chunk, _ in resp.content.iter_chunks():
...                 await stream.append_bytes(chunk)
...     await stream.mark_complete()
...     acc = b''
...     async for chunk in stream_bytes(ipfs_hash, stream):
...         acc += chunk
...     print(acc)
...
>>> asyncio.run(test())
b'hello'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipfs_car_decoder-0.1.1.tar.gz (11.4 kB view hashes)

Uploaded Source

Built Distribution

ipfs_car_decoder-0.1.1-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page