Files
wekan/tests/collectionFsMoveStreams.test.cjs
T
Lauri Ojansivu cd054f9964 Stream files moved to or from the old CollectionFS storage.
Admin Panel > Attachments > Move read each file whole into memory: out of
CollectionFS it gathered the GridFS download into one Buffer and wrote it
with writeFileSync, into CollectionFS it read the source storage whole and
then uploaded it. Both now pipe: the GridFS download stream into the new
file, and the storage's read stream into the GridFS upload, chunk by chunk.
A copy that fails leaves no half file, and a missing binary still names the
attachment. Removed from TODO Later.

Thanks to markusst1982 and xet7 !
2026-10-09 23:06:49 +03:00

26 lines
1.4 KiB
JavaScript

'use strict';
// Moving files to or from the old CollectionFS storage streams them chunk by
// chunk instead of reading each whole file into memory (#6745).
// Run: node tests/collectionFsMoveStreams.test.cjs
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const store = read('models/lib/collectionFsStore.js');
const move = read('server/attachmentBulkMove.js');
// Out of CollectionFS: the GridFS download stream is piped to the new file.
assert.match(store, /export function openCollectionFsStream\(item\) \{[\s\S]*?bucket\.openDownloadStream\(gridFsId\)[\s\S]*?return stream\.pipe\(out\);/);
assert.match(move, /stream: openCollectionFsStream\(item\),/);
assert.match(move, /info\.stream\.pipe\(out\);/);
// Into CollectionFS: the storage read stream is piped into the GridFS upload.
assert.match(store, /if \(source && typeof source\.pipe === 'function'\) \{[\s\S]*?source\.pipe\(uploadStream\);/);
assert.match(move, /\}, openStrategyStream\(strategy\)\);/);
// Negative: no whole-file buffering is left on either path.
assert.doesNotMatch(store, /Buffer\.concat|readCollectionFsBuffer/);
assert.doesNotMatch(move, /readStrategyBuffer|createMeteorFilesDocFromBuffer|writeFileSync\(fullPath|Buffer\.concat\(chunks\)/);
console.log('collectionFsMoveStreams: 7 checks passed');