From 12d675e0e4c5e9f1b28a518fb990ceac22cd31c5 Mon Sep 17 00:00:00 2001 From: Jon Lippincott Date: Tue, 12 Nov 2019 12:49:46 +0100 Subject: [PATCH] If file doesn't exist, throw an exception --- lib/render.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/render.js b/lib/render.js index 8bc7df0..aa1df1b 100644 --- a/lib/render.js +++ b/lib/render.js @@ -1,4 +1,5 @@ var spawn = require('child_process').spawn +var fs = require('fs') //var Canvas = require('canvas') var defaultSetting = { @@ -32,6 +33,10 @@ function getPcmData (filename, options, sampleCallback, endCallback) { sampleRate = options.sampleRate } + if (!fs.existsSync(filename)) { + throw `File doesn't exist: ${filename}` + } + var ffmpeg = spawn('ffmpeg', ['-i', filename, '-f', 's16le', '-ac', channels, '-acodec', 'pcm_s16le', '-ar', sampleRate, '-y', 'pipe:1']) @@ -161,7 +166,7 @@ module.exports = function render (url, options, cb) { //canvasContext.fillStyle = options.baselineColor //canvasContext.fillRect(0, options.baseline - (options.baselineWidth / 2), options.width, options.baselineWidth) } - cb(null, canvas.toBuffer()) + //cb(null, canvas.toBuffer()) if (options.normalizedValuesCallback) { options.normalizedValuesCallback(normalizedVals);