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 (#4282)
Browse files Browse the repository at this point in the history
If you write to an MFS directory with `rawLeaves: true`, it'll error out when doing a read saying `Error: /example-0/example.txt was not a file`.

This accounts for that case by handling the `raw` type the same as a file.

Co-authored-by: Mauve Signweaver <RangerMauve@mauve.moe>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
  • Loading branch information
3 people authored Jan 11, 2023
1 parent fa578ba commit 0cfcaf6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 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,15 @@ 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
})
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)
})

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 0cfcaf6

Please sign in to comment.