Skip to content

Commit fb8f39e

Browse files
authored
Merge pull request #824 from PaulHax/fix-nii-gz
fix: support loading .nii.gz files from local file system
2 parents c736369 + 0c153b0 commit fb8f39e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/io/import/processors/importSingleFile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const importSingleFile: ImportHandler = async (dataSource) => {
4343
return asLoadableResult(dataID, dataSource, 'model');
4444
}
4545

46-
throw new Error('Data reader did not produce a valid dataset');
46+
throw new Error(
47+
`Failed to import "${dataSource.file.name}". The file may be corrupted or in an unsupported format variant.`
48+
);
4749
};
4850

4951
export default importSingleFile;

src/io/import/processors/updateFileMimeType.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { Skip } from '@/src/utils/evaluateChain';
22
import { getFileMimeType } from '@/src/io';
33
import { ImportHandler, asIntermediateResult } from '@/src/io/import/common';
4+
import { MIME_TYPES } from '@/src/io/mimeTypes';
45

56
/**
67
* Transforms a file data source to have a mime type
78
* @param dataSource
89
*/
910
const updateFileMimeType: ImportHandler = async (dataSource) => {
10-
if (dataSource.type !== 'file' || dataSource.fileType !== '') return Skip;
11+
if (dataSource.type !== 'file') return Skip;
12+
13+
const knownType =
14+
dataSource.fileType !== '' && MIME_TYPES.has(dataSource.fileType);
15+
if (knownType) {
16+
return Skip;
17+
}
1118

1219
const mime = await getFileMimeType(dataSource.file);
20+
1321
if (!mime) {
14-
throw new Error('File is unsupported');
22+
throw new Error(
23+
`Unrecognized file type for "${dataSource.file.name}". This file format is not supported.`
24+
);
1525
}
1626

1727
return asIntermediateResult([

0 commit comments

Comments
 (0)