diff --git a/lib/zip/stream.js b/lib/zip/stream.js index fbbd2c2..c69e254 100644 --- a/lib/zip/stream.js +++ b/lib/zip/stream.js @@ -7,6 +7,8 @@ const TarStream = require('../tar/stream'); class ZipStream extends TarStream { _init() { const zipfile = this._zipfile = new yazl.ZipFile(); + // yazl emits errors reading the files (stat, open, size change) on the ZipFile itself + zipfile.on('error', err => this.emit('error', err)); const stream = zipfile.outputStream; stream.on('end', () => this.push(null)); stream.on('data', chunk => this.push(chunk)); diff --git a/test/zip/index.test.js b/test/zip/index.test.js index 8434870..efa26b4 100644 --- a/test/zip/index.test.js +++ b/test/zip/index.test.js @@ -111,6 +111,20 @@ describe('test/zip/index.test.js', () => { assert(fs.existsSync(destFile)); }); + it('zip.compressDir(dir, destFile) should reject when a file cannot be read', async () => { + if (isWindows || process.getuid() === 0) return; + const sourceDir = path.join(os.tmpdir(), randomUUID()); + fs.mkdirSync(sourceDir); + fs.writeFileSync(path.join(sourceDir, 'locked.txt'), 'locked'); + fs.chmodSync(path.join(sourceDir, 'locked.txt'), 0o000); + destDir = path.join(os.tmpdir(), randomUUID()); + fs.mkdirSync(destDir, { recursive: true }); + await assert.rejects( + compressing.zip.compressDir(sourceDir, path.join(destDir, 'out.zip')), + { code: 'EACCES' } + ); + }); + it('zip.compressDir(dir, destStream, { ignoreBase: true })', async () => { const sourceDir = path.join(__dirname, '..', 'fixtures'); destDir = path.join(os.tmpdir(), randomUUID());