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

Commit

Permalink
fix: Allow reading rawLeaves in MFS
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauve Signweaver authored and Mauve Signweaver committed Jan 10, 2023
1 parent e85e5b6 commit ebd01bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit ebd01bc

Please sign in to comment.