3 Star 0 Fork 0

mirrors_rvagg/js-car-zero-length-blocks

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

js-car-zero-length-blocks

Debugging why @ipld/car is failing with car files that contain zero length files/blocks.

Usage

$ node car-test.mjs
Usage: node car-test.mjs --empty-block=true|false --car-file=true|false [--skip-write]

Output

No empty block, async iterable

Add two normal IPLD blocks. Connect writer async iterable output directly to reader.

$ node car-test.mjs --empty-block=false --car-file=false 
Insert empty block: false
Use .car file: false

Put cidA CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei) Uint8Array(2) [ 1, 2 ]
Put cidC CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4) Uint8Array(2) [ 3, 4 ]
Got cidA {
  bytes: Uint8Array(2) [ 1, 2 ],
  cid: CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei)
}
Got cidC {
  bytes: Uint8Array(2) [ 3, 4 ],
  cid: CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4)
} 

This works as expected.

Empty block, async iterable

Add a normal IPLD blocks, then a IPLD block with no data, and finally another normal IPLD block. Connect writer async iterable output directly to reader.

$ node car-test.mjs --empty-block=true --car-file=false 
Insert empty block: true
Use .car file: false

Put cidA CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei) Uint8Array(2) [ 1, 2 ]
Put cidB CID(bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku) Uint8Array(0) []
Got cidA {
  bytes: Uint8Array(2) [ 1, 2 ],
  cid: CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei)
}
Got cidB {
  bytes: Uint8Array(0) [],
  cid: CID(bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku)
}
Got cidC undefined WRONG!!
Put cidC CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4) Uint8Array(2) [ 3, 4 ]

This fails. The reader tried to read the third block before it was written, and got undefined as a result.

No empty block, CAR file

Add two normal IPLD blocks. Write out to a .car file on the filesystem and read it.

$ node car-test.mjs --empty-block=false --car-file=true
Insert empty block: false
Use .car file: true
Filename: example.car
Skip write: false

Put cidA CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei) Uint8Array(2) [ 1, 2 ]
Put cidC CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4) Uint8Array(2) [ 3, 4 ]
Got cidA {
  bytes: Uint8Array(2) [ 1, 2 ],
  cid: CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei)
}
Got cidC {
  bytes: Uint8Array(2) [ 3, 4 ],
  cid: CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4)
}

This works as expected.

A file named example.car was written to the filesystem. Let's try re-reading that (skip the writing phase).

$ node car-test.mjs --empty-block=false --car-file=true --skip-write
Insert empty block: false
Use .car file: true
Filename: example.car
Skip write: true

Got cidA {
  bytes: Uint8Array(2) [ 1, 2 ],
  cid: CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei)
}
Got cidC {
  bytes: Uint8Array(2) [ 3, 4 ],
  cid: CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4)
}

This is the same correct result as before.

Empty block, CAR file

Add a normal IPLD blocks, then a IPLD block with no data, and finally another normal IPLD block. Write out to a .car file on the filesystem and read it.

$ node car-test.mjs  --empty-block=true --car-file=true
Insert empty block: true
Use .car file: true
Filename: example-empty.car
Skip write: false

Put cidA CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei) Uint8Array(2) [ 1, 2 ]
Put cidB CID(bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku) Uint8Array(0) []
Got cidA {
  bytes: Uint8Array(2) [ 1, 2 ],
  cid: CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei)
}
Got cidB {
  bytes: Uint8Array(0) [],
  cid: CID(bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku)
}
Got cidC undefined WRONG!!
Put cidC CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4) Uint8Array(2) [ 3, 4 ]

This also fails. The reader tried to read the third block before it was written, and got undefined as a result.

A file named example-empty.car was written to the filesystem. Let's try re-reading that (skip the writing phase).

$ node car-test.mjs --empty-block=true --car-file=true --skip-write
Insert empty block: true
Use .car file: true
Filename: example-empty.car
Skip write: true

Got cidA {
  bytes: Uint8Array(2) [ 1, 2 ],
  cid: CID(bafkreifbfby75yqq7odbski6v2qziwa4xustdzfsg5m5ejpwqbush5rsei)
}
Got cidB {
  bytes: Uint8Array(0) [],
  cid: CID(bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku)
}
Got cidC {
  bytes: Uint8Array(2) [ 3, 4 ],
  cid: CID(bafkreiam4okax27swivf2iii5tymg2fakqoh4pcfoa7ykqesdnhk7sbji4)
}

Interesting! It read the .car file correctly. The incorrect result only seems to happen when the file is being read at the same time as it is written.

License

MIT

空文件

发行版

暂无发行版

贡献者 (1)

全部

近期动态

接近4年前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_rvagg/js-car-zero-length-blocks.git
git@gitee.com:mirrors_rvagg/js-car-zero-length-blocks.git
mirrors_rvagg
js-car-zero-length-blocks
js-car-zero-length-blocks
main

搜索帮助