From ebd01bc90d86bfbfdd955ca60c3ec5178c6a8936 Mon Sep 17 00:00:00 2001 From: Mauve Signweaver Date: Mon, 9 Jan 2023 22:17:38 -0500 Subject: [PATCH 1/2] fix: Allow reading rawLeaves in MFS --- packages/interface-ipfs-core/src/files/read.js | 8 ++++++++ packages/ipfs-core/src/components/files/read.js | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/interface-ipfs-core/src/files/read.js b/packages/interface-ipfs-core/src/files/read.js index 1212cc4165..5204a7b24d 100644 --- a/packages/interface-ipfs-core/src/files/read.js +++ b/packages/interface-ipfs-core/src/files/read.js @@ -112,6 +112,14 @@ export function testRead (factory, options) { expect(testFileData).to.eql(fixtures.smallFile.data) }) + it('should be able to read rawLeaves files', async () => { + const { cid } = await ipfs.add(fixtures.smallFile.data, { + rawLeaves: true + }) + const testFileData = uint8ArrayConcat(await all(ipfs.files.read(`/ipfs/${cid}`))) + expect(testFileData).to.eql(fixtures.smallFile.data) + }) + describe('with sharding', () => { /** @type {import('ipfs-core-types').IPFS} */ let ipfs diff --git a/packages/ipfs-core/src/components/files/read.js b/packages/ipfs-core/src/components/files/read.js index a66ba0d78c..28b132f12c 100644 --- a/packages/ipfs-core/src/components/files/read.js +++ b/packages/ipfs-core/src/components/files/read.js @@ -39,8 +39,8 @@ export function createRead (context) { const mfsPath = await toMfsPath(context, path, options) const result = await exporter(mfsPath.mfsPath, context.repo.blocks) - if (result.type !== 'file') { - throw errCode(new Error(`${path} was not a file`), 'ERR_NOT_FILE') + if (result.type !== 'file' && result.type !== 'raw') { + throw errCode(new Error(`${path} was not a file or raw bytes`), 'ERR_NOT_FILE') } if (!result.content) { From b455cd2f4a759a0b36169a91ff4da5992722dc78 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 11 Jan 2023 16:39:36 +0000 Subject: [PATCH 2/2] fix: fix up test to run against kubo --- packages/interface-ipfs-core/src/files/read.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/interface-ipfs-core/src/files/read.js b/packages/interface-ipfs-core/src/files/read.js index 5204a7b24d..32ea03e468 100644 --- a/packages/interface-ipfs-core/src/files/read.js +++ b/packages/interface-ipfs-core/src/files/read.js @@ -116,7 +116,8 @@ export function testRead (factory, options) { const { cid } = await ipfs.add(fixtures.smallFile.data, { rawLeaves: true }) - const testFileData = uint8ArrayConcat(await all(ipfs.files.read(`/ipfs/${cid}`))) + await ipfs.files.cp(`/ipfs/${cid}`, '/raw-leaves.txt') + const testFileData = uint8ArrayConcat(await all(ipfs.files.read('/raw-leaves.txt'))) expect(testFileData).to.eql(fixtures.smallFile.data) })