fix: binary file corruption in brain.import() with preserveSource
## Bug Fix
**Issue**: When using `brain.import(filePath, { preserveSource: true })`,
binary files (PDFs, images, Excel) were NOT being preserved in VFS, causing
Z_DATA_ERROR when trying to read them back.
**Root Cause**: ImportCoordinator line 444 checked for `type === 'buffer'`,
but normalizeSource() returns `type: 'path'` for file paths (the most common
case). This caused `sourceBuffer = undefined`, silently failing to preserve
the source file.
**Fix**: Changed condition to `Buffer.isBuffer(normalizedSource.data)` to
handle both Buffer objects and file paths correctly.
## Code Changes
**src/import/ImportCoordinator.ts:445**
```typescript
// BEFORE (v5.1.1)
sourceBuffer: normalizedSource.type === 'buffer' ? normalizedSource.data as Buffer : undefined
// AFTER (v5.1.2)
sourceBuffer: Buffer.isBuffer(normalizedSource.data) ? normalizedSource.data as Buffer : undefined
```
## Testing
Added comprehensive tests in `tests/unit/import/preserve-source-fix.test.ts`:
- ✅ File path import with preserveSource: true (main fix)
- ✅ Verify preserveSource: false works correctly
- ✅ Binary file integrity (no corruption)
## Impact
**Before**: Workshop team experienced Z_DATA_ERROR reading imported PDFs
**After**: Binary files correctly preserved and readable from VFS
## Related Issues
Fixes bug reported in:
/media/dpsifr/storage/home/Projects/brain-cloud/apps/workshop/BRAINY_BUG_REPORT.md
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6587b9e98c
commit
97eb6eec2c
2 changed files with 143 additions and 1 deletions
|
|
@ -441,7 +441,8 @@ export class ImportCoordinator {
|
|||
groupBy: opts.groupBy,
|
||||
customGrouping: opts.customGrouping,
|
||||
preserveSource: opts.preserveSource,
|
||||
sourceBuffer: normalizedSource.type === 'buffer' ? normalizedSource.data as Buffer : undefined,
|
||||
// v5.1.2: Fix sourceBuffer for file paths - type is 'path' not 'buffer' from normalizeSource()
|
||||
sourceBuffer: Buffer.isBuffer(normalizedSource.data) ? normalizedSource.data as Buffer : undefined,
|
||||
sourceFilename: normalizedSource.filename || `import.${detection.format}`,
|
||||
createRelationshipFile: true,
|
||||
createMetadataFile: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue