cleanup and logging
This commit is contained in:
@@ -6,6 +6,8 @@ logger = require "logger-sharelatex"
|
||||
module.exports = OutputFileOptimiser =
|
||||
|
||||
optimiseFile: (src, dst, callback = (error) ->) ->
|
||||
# check output file (src) and see if we can optimise it, storing
|
||||
# the result in the build directory (dst)
|
||||
if src.match(/\.pdf$/)
|
||||
OutputFileOptimiser.optimisePDF src, dst, callback
|
||||
else
|
||||
@@ -19,12 +21,13 @@ module.exports = OutputFileOptimiser =
|
||||
proc = spawn("qpdf", args)
|
||||
stdout = ""
|
||||
proc.stdout.on "data", (chunk) ->
|
||||
stdout += chunk.toString()
|
||||
proc.on "error", callback
|
||||
stdout += chunk.toString()
|
||||
proc.on "error", callback
|
||||
proc.on "close", (code) ->
|
||||
if code != 0
|
||||
logger.warn {directory, code}, "qpdf returned error"
|
||||
return callback null
|
||||
fs.rename tmpOutput, dst, (err) ->
|
||||
# could log an error here
|
||||
callback null
|
||||
if err?
|
||||
logger.warn {tmpOutput, dst}, "failed to rename output of qpdf command"
|
||||
callback err
|
||||
|
||||
Reference in New Issue
Block a user