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

Commit 0cfcaf6

Browse files
RangerMauveMauve Signweaverachingbrain
authored
fix: allow reading rawLeaves in MFS (#4282)
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 <[email protected]> Co-authored-by: Alex Potsides <[email protected]>
1 parent fa578ba commit 0cfcaf6

File tree

2 files changed

+11
-2
lines changed
  • packages
    • interface-ipfs-core/src/files
    • ipfs-core/src/components/files

2 files changed

+11
-2
lines changed

packages/interface-ipfs-core/src/files/read.js

+9
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ export function testRead (factory, options) {
112112
expect(testFileData).to.eql(fixtures.smallFile.data)
113113
})
114114

115+
it('should be able to read rawLeaves files', async () => {
116+
const { cid } = await ipfs.add(fixtures.smallFile.data, {
117+
rawLeaves: true
118+
})
119+
await ipfs.files.cp(`/ipfs/${cid}`, '/raw-leaves.txt')
120+
const testFileData = uint8ArrayConcat(await all(ipfs.files.read('/raw-leaves.txt')))
121+
expect(testFileData).to.eql(fixtures.smallFile.data)
122+
})
123+
115124
describe('with sharding', () => {
116125
/** @type {import('ipfs-core-types').IPFS} */
117126
let ipfs

packages/ipfs-core/src/components/files/read.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export function createRead (context) {
3939
const mfsPath = await toMfsPath(context, path, options)
4040
const result = await exporter(mfsPath.mfsPath, context.repo.blocks)
4141

42-
if (result.type !== 'file') {
43-
throw errCode(new Error(`${path} was not a file`), 'ERR_NOT_FILE')
42+
if (result.type !== 'file' && result.type !== 'raw') {
43+
throw errCode(new Error(`${path} was not a file or raw bytes`), 'ERR_NOT_FILE')
4444
}
4545

4646
if (!result.content) {

0 commit comments

Comments
 (0)