From 746680779de6da968c655050d37250490351886a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvin=20Guti=C3=A9rrez?= Date: Tue, 15 Oct 2019 11:52:53 +0100 Subject: [PATCH 1/3] emit gzip_finish event --- index.js | 3 +++ lib/filerotator.js | 6 +++++- lib/rotatingfilestream.js | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bb9b954..8d75319 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,9 @@ function RotatingFileStreamFactory(options) { if (!rfs) { rfs = RotatingFileStream(options_copy); + rfs.on('gzip_finish', path => { + options.on_gzip_finish && options.on_gzip_finish(path); + }); existingFilesStreams[options_copy.path] = rfs; diff --git a/lib/filerotator.js b/lib/filerotator.js index 4683f28..02abf8e 100644 --- a/lib/filerotator.js +++ b/lib/filerotator.js @@ -46,7 +46,11 @@ function FileRotator(logpath, totalFiles, totalSize, gzip) { .pipe(zlib.createGzip()) .pipe(fs.createWriteStream(zippedPath)) .on('finish', function () { - fs.unlink(unzippedPath, next); + fs.unlink(unzippedPath, () => { + base.emit('gzip_finish', zippedPath); + next(); + }); + }) } diff --git a/lib/rotatingfilestream.js b/lib/rotatingfilestream.js index 6b1460b..07ab1fb 100644 --- a/lib/rotatingfilestream.js +++ b/lib/rotatingfilestream.js @@ -35,6 +35,9 @@ function RotatingFileStream(options) { var shared = options.shared; var rotator = FileRotator(path, totalFiles, totalSize, gzip); + rotator.on('gzip_finish', function(zippedPath) { + base.emit('gzip_finish', zippedPath); + }); var stream = null; var streambytesWritten = 0; From 935e7b0ac2957ab4821ffe62f48621d58e066ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvin=20Guti=C3=A9rrez?= Date: Wed, 16 Oct 2019 10:04:38 +0100 Subject: [PATCH 2/3] Remove uneeded event callback --- index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.js b/index.js index 8d75319..bb9b954 100644 --- a/index.js +++ b/index.js @@ -26,9 +26,6 @@ function RotatingFileStreamFactory(options) { if (!rfs) { rfs = RotatingFileStream(options_copy); - rfs.on('gzip_finish', path => { - options.on_gzip_finish && options.on_gzip_finish(path); - }); existingFilesStreams[options_copy.path] = rfs; From 7756462e74b78f964877b4baceddac197b99515f Mon Sep 17 00:00:00 2001 From: melvin-gutierrez-sbz <49437576+melvin-gutierrez-sbz@users.noreply.github.com> Date: Wed, 16 Oct 2019 11:16:16 +0100 Subject: [PATCH 3/3] Update lib/filerotator.js Co-Authored-By: David Gaya --- lib/filerotator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filerotator.js b/lib/filerotator.js index 02abf8e..04666bf 100644 --- a/lib/filerotator.js +++ b/lib/filerotator.js @@ -45,7 +45,7 @@ function FileRotator(logpath, totalFiles, totalSize, gzip) { }) .pipe(zlib.createGzip()) .pipe(fs.createWriteStream(zippedPath)) - .on('finish', function () { + .on('close', function () { fs.unlink(unzippedPath, () => { base.emit('gzip_finish', zippedPath); next();