Skip to content

Commit 720625a

Browse files
Fix backup restore failing on large zips with Z_BUF_ERROR
unzipper.Extract().promise() has a race condition on large zip files where the promise resolves before write buffers are flushed, causing zlib to see a premature end-of-stream. Switch both backup restore and Obsidian import to unzipper.Open.file() which reads the central directory first and is reliable for large archives. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 55af24b commit 720625a

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

server/src/routes/backup.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,10 @@ async function streamRestoreFromZip(req, res, zipPath, displayName, { deleteSour
305305
console.log('[RESTORE] Extracting backup:', displayName);
306306

307307
await fs.mkdir(extractDir, { recursive: true });
308-
await require('fs').createReadStream(zipPath)
309-
.pipe(unzipper.Extract({ path: extractDir }))
310-
.promise();
308+
// Open via central directory (more reliable for large zips than the
309+
// streaming Extract().promise() which can resolve before writes flush).
310+
const zipDir = await unzipper.Open.file(zipPath);
311+
await zipDir.extract({ path: extractDir, concurrency: 4 });
311312

312313
const sqlFilePath = path.join(extractDir, 'database.sql');
313314
const extractedUploadsPath = path.join(extractDir, 'uploads');

server/src/routes/import-obsidian.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ router.post('/', blockInDemo, upload.fields([
126126
fs.mkdirSync(extractDir, { recursive: true });
127127

128128
send('status', { message: 'Extracting archive...' });
129-
await fs.createReadStream(zipPath)
130-
.pipe(unzipper.Extract({ path: extractDir }))
131-
.promise();
129+
const zipDir = await unzipper.Open.file(zipPath);
130+
await zipDir.extract({ path: extractDir, concurrency: 4 });
132131

133132
importFiles = collectMdFiles(extractDir);
134133
resourceMap = buildResourceMap(extractDir);

0 commit comments

Comments
 (0)