markdown-word icon indicating copy to clipboard operation
markdown-word copied to clipboard

file not readable

Open celevra opened this issue 9 years ago • 1 comments

Hi,

tried to convert this MD to word: http://codemirror.net/mode/markdown/

got an unreadable File, no error, is there a debug switch?

regards

celevra avatar Jun 18 '15 12:06 celevra

The problem is in line 789, where fs.writeFile is called, but the callback is an empty function. The solution could be to use fs.writeFileSync, or to refactor to handle the callback of the async call correctly.

https://github.com/Trimeego/markdown-word/blob/master/lib/markdown-word.js#L789

                  return buff = archive.toBuffer(function(result) {
                    return fs.writeFile(outputFile, result, function() {});
                  });

What happens is the callback does nothing, so your program continues and when it tries to use the file this function creates, it is too early because it didn't wait for the callback from writeFile so the file does not exist yet.

mnebuerquo avatar Jul 19 '15 18:07 mnebuerquo