diff --git a/epub.js b/epub.js index 44c7354..ccb7940 100644 --- a/epub.js +++ b/epub.js @@ -666,8 +666,8 @@ class EPub extends EventEmitter { // replace links str = str.replace(/(\shref\s*=\s*["']?)([^"'\s>]*?)(["'\s>])/g, (function (o, a, b, c) { - var linkparts = b && b.split("#"), - link = path.concat([(linkparts.shift() || "")]).join("/").trim(), + var linkparts = b && b.split("#"); + var link = linkparts.length ? path.concat([(linkparts.shift() || "")]).join("/").trim() : '', element; for (i = 0, len = keys.length; i < len; i++) { @@ -718,7 +718,11 @@ class EPub extends EventEmitter { return; } - var str = data.toString("utf-8"); + var str = ""; + if (data) { + str = data.toString("utf-8"); + }; + callback(null, str);