Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not loading images #16

Open
Emmy02 opened this issue May 7, 2015 · 4 comments
Open

Not loading images #16

Emmy02 opened this issue May 7, 2015 · 4 comments

Comments

@Emmy02
Copy link

Emmy02 commented May 7, 2015

Greetings, I want to congratulate you, because your project is very usefull, I just want to know why the images are not loaded in the getChapter function?

@julien-c
Copy link
Owner

Hi @Emmy02 – can you try the getFile function instead?

@Emmy02
Copy link
Author

Emmy02 commented May 12, 2015

Hi, I tried getFile function, it's download the entire file, instead rendering images.

@srghma
Copy link

srghma commented Oct 29, 2021

with

function parse(epub) {
  return new Promise((resolve, reject) => {
    epub.on("error", function(error) {
      console.log("ERROR\n-----")
      throw error
    })

    epub.on("end", function(error){
      if (error) { reject({ on: "end", error }) }
      else { resolve() }
    })

    epub.parse()
  })
}

function getChapter(epub, id) {
  return new Promise((resolve, reject) => {
    epub.getChapter(id, function(error, data){
      if(error){
        reject(error)
        return
      }
      resolve(data)
    })
  })
}

function getImage(epub, id) {
  return new Promise((resolve, reject) => {
    epub.getImage(id, function(error, data, mimeType){
      if(error){
        reject(error)
        return
      }
      resolve({ data, mimeType })
    })
  })
}

var EPub = require("epub")

var epub = new EPub("elon-musk.epub", "/imagewebroot/", "/articlewebroot/")

const parseResult = await parse(epub)

console.log(parseResult)
console.log("METADATA:\n")
console.log(epub.metadata)

console.log("\nSPINE:\n")
console.log(epub.flow)

console.log("\nTOC:\n")
console.log(epub.toc)

data = await getChapter(epub, epub.spine.contents[2].id)

image = await getImage(epub, 'x001.jpg')

I get

> data = await getChapter(epub, epub.spine.contents[2].id)
'<div class="chatu">\n' +
  '    <img alt="" />\n' +
  '\n' +
  '    <p class="tushuo">马斯克的外祖父天生爱冒险,除了常自己开飞机到各地旅行,还经常带着孩子们到荒野去探险,照片中的宁静,让人对这些旅行的危险 性产生错觉。</p>\n' +
  '  </div>\n' +

as You see there is no id in <img alt="" />

@srghma
Copy link

srghma commented Oct 29, 2021

I can confirm getFile works

> data = await getFile(epub, epub.spine.contents[2].id)
<Buffer 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 75 74 66 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 6e ... 8082 more bytes>
> data.toString()
'<?xml version="1.0" encoding="utf-8" standalone="no"?>\r\n' +
  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\r\n' +
  '  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\r\n' +
  '\r\n' +
  '<html xmlns="http://www.w3.org/1999/xhtml">\r\n' +
  '<head>\r\n' +
  '  <title></title>\r\n' +
  '  <link href="../Styles/stylesheet_20151118.css" rel="stylesheet" type="text/css" />\r\n' +
  '  <link href="../Styles/stylesheet_zmx.css" rel="stylesheet" type="text/css" />\r\n' +
  '</head>\r\n' +
  '\r\n' +
  '<body>\r\n' +
  '  <div class="chatu">\r\n' +
  '    <img alt="" src="../Images/004.jpg" />\r\n' +
  '\r\n' +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants