a9a9f6ee6b
* migrate recover_zip_from_backup from archiver to zip-stream Replace the `archiver` package with `zip-stream` (the lower-level library that `archiver` wraps) in the `recover_zip_from_backup.mjs` script and `backupArchiver.mjs` library. The `archiver` package has known issues with hanging when creating large zip files and is no longer actively maintained. Changes: - Add `zip-stream@^7.0.2` as a direct dependency - Update `backupArchiver.mjs` to use promisified `ZipStream.entry()` instead of `Archiver.append()` - Rewrite `recover_zip_from_backup.mjs` to use `ZipStream` with `stream/promises.pipeline` for cleaner async flow - Keep `archiver` dependency for `project_archive.js` (separate code path) Agent-Logs-Url: https://github.com/overleaf/internal/sessions/0df27a8b-97f1-43cc-ac26-f5247a84313f Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * extract finalize timeout to named constant Agent-Logs-Url: https://github.com/overleaf/internal/sessions/0df27a8b-97f1-43cc-ac26-f5247a84313f Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * convert recover_zip.js to zip-stream, remove finalize timeout, add verbose logging Agent-Logs-Url: https://github.com/overleaf/internal/sessions/9380d08a-d813-4e9f-a2ac-4891122c163b Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * add acceptance tests for recover_zip_from_backup in raw and latest modes Agent-Logs-Url: https://github.com/overleaf/internal/sessions/9380d08a-d813-4e9f-a2ac-4891122c163b Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * fix comment formatting in recover_zip_from_backup.mjs Agent-Logs-Url: https://github.com/overleaf/internal/sessions/9380d08a-d813-4e9f-a2ac-4891122c163b Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * restore EventEmitter.defaultMaxListeners in recover_zip.js, add acceptance test Agent-Logs-Url: https://github.com/overleaf/internal/sessions/e7443126-22d5-4d0e-a176-a7a5dba49ffd Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * fix formatting * refactor: simplify stream handling by using named imports for pipeline * fix blob hash verification in backup acceptance tests * fix recover_zip script and tests * fix: exit with non-zero status on error in recover_zip.js Agent-Logs-Url: https://github.com/overleaf/internal/sessions/ef3f109b-488f-47c9-84a5-b5269387166a Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> * migrate from npm to yarn --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: briangough <7457354+briangough@users.noreply.github.com> Co-authored-by: Brian Gough <briangough@users.noreply.github.com> GitOrigin-RevId: 6255f9610f3c846790e2ed8b1979ac08b7effece
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
// @ts-check
|
|
/**
|
|
* Promises are promises and streams are streams, and ne'er the twain shall
|
|
* meet.
|
|
* @module
|
|
*/
|
|
'use strict'
|
|
|
|
const { pipeline } = require('node:stream/promises')
|
|
const zlib = require('node:zlib')
|
|
const { WritableBuffer } = require('@overleaf/stream-utils')
|
|
|
|
/**
|
|
* Create a promise for the result of reading a stream to a buffer.
|
|
*
|
|
* @param {import('node:stream').Readable} readStream
|
|
* @return {Promise<Buffer>}
|
|
*/
|
|
async function readStreamToBuffer(readStream) {
|
|
const bufferStream = new WritableBuffer()
|
|
await pipeline(readStream, bufferStream)
|
|
return bufferStream.contents()
|
|
}
|
|
|
|
exports.readStreamToBuffer = readStreamToBuffer
|
|
|
|
/**
|
|
* Create a promise for the result of un-gzipping a stream to a buffer.
|
|
*
|
|
* @param {NodeJS.ReadableStream} readStream
|
|
* @return {Promise<Buffer>}
|
|
*/
|
|
async function gunzipStreamToBuffer(readStream) {
|
|
const gunzip = zlib.createGunzip()
|
|
const bufferStream = new WritableBuffer()
|
|
await pipeline(readStream, gunzip, bufferStream)
|
|
return bufferStream.contents()
|
|
}
|
|
|
|
exports.gunzipStreamToBuffer = gunzipStreamToBuffer
|