Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: allow reading rawLeaves in MFS #4282

Merged
merged 3 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/interface-ipfs-core/src/files/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core/src/components/files/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down