Giter Site home page Giter Site logo

iepub's Introduction

iepub

EPUB格式读写库,

支持从文件和内存读取和生成EPUB电子书

生成

  • 可以使用EpubBook结构体手动生成epub
  • (推荐)使用EpubBuilder快速生成
use iepub::EpubHtml;
use iepub::EpubBuilder;

EpubBuilder::default()
    .with_title("书名")
    .with_creator("作者")
    .with_date("2024-03-14")
    .with_description("一本好书")
    .with_identifier("isbn")
    .with_publisher("行星出版社")
    .add_chapter(
        EpubHtml::default()
            .with_file_name("0.xml")
            .with_data("<p>锻炼</p>".to_string().as_bytes().to_vec()),
    )
    .add_assets("1.css", "p{color:red}".to_string().as_bytes().to_vec())
    .metadata("s", "d")
    .metadata("h", "m")
    .file("target/build.epub")
    .unwrap();

读取

 use iepub::{reader::read_from_vec, reader::read_from_file, EpubHtml};
let mut data = Vec::new();// epub的二进制数据

let mut book = read_from_vec(data);
// 从文件读取
let mut bbook = read_from_file("epub格式文件绝对路径");

// 注意,默认情况下读取采用懒加载,上述代码只完成了基础结构读取,包括目录,文件列表等等,具体某个章节或者资源的数据将会推迟到第一次调用`data()`方法时读取
// 例如

let mut chap = book.get_chapter("0.xhtml").unwrap();
let data = chap.data();// 此时将会实际读取并解析文件
let data2 = chap.data();// 第二次不会再读取文件了

注意事项

iepub使用EpubHtml来存储章节内容,但是EpubHtml#data实际只会存储 html>body 节点内的内容,并且不包括body节点的属性(attribute),其他比如样式表将会存放在其他属性中

命令行工具

tool目录为命令行工具

目前支持

  • 获取元数据,如标题、作者
  • 修改元数据
  • 提取封面
  • 提取所有图片
  • 提取某章节文本
  • 获取目录

可通过-h获取使用方法说明

iepub's People

Contributors

inkroom avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.