From 6158c1b1d42cd3d46d0704f45364b8062bd815bf Mon Sep 17 00:00:00 2001 From: Mathieu Simard Date: Fri, 2 Feb 2018 08:57:04 -0500 Subject: [PATCH] When writing the diff file, Niffy does not wait for the close of the stream. We encountered this issue while adding an upload to S3 to our after phase. The file uploaded to S3 contained partial data; indicating that there was two process competing to write and read the file. Fix is a simple on close handler. We also bumped the version of pngjs. note: potential bug/omission found in pngjs https://github.com/lukeapage/pngjs/blob/master/lib/png.js#L43 --- lib/diff.js | 9 ++++++--- package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/diff.js b/lib/diff.js index b5688ee..f246c9c 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -33,7 +33,7 @@ function* diff(pathA, pathB, pathDiff) { debug('finished diffing imgs %s', new Date()); - writePNG(png, pathDiff); + yield thunkify(writePNG)(png, pathDiff); debug('finished img diffing %s', new Date()); @@ -64,10 +64,13 @@ function readPNG(path, callback) { * @param {String} path */ -function writePNG(png, path) { +function writePNG(png, path, callback) { png .pack() - .pipe(fs.createWriteStream(path)); + .pipe(fs.createWriteStream(path)) + .on('close', function() { + callback(null, this); + }); } /** diff --git a/package.json b/package.json index a76527c..e5508ec 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "defaults": "^1.0.2", "mkdirp": "^0.5.1", "nightmare": "^2.0.3", - "pngjs": "^3.0.1", + "pngjs": "^3.3.1", "sprintf-js": "^1.0.3", "thunkify": "^2.1.2", "vo": "^1.0.3"