Coder Social home page Coder Social logo

orthros / dart-epub Goto Github PK

View Code? Open in Web Editor NEW
214.0 11.0 220.0 90.17 MB

Epub Reader and Writer for Dart

License: MIT License

Dart 98.82% Shell 0.21% Java 0.18% Objective-C 0.37% HTML 0.30% CSS 0.12%
epub dart epub-reader dart-epub flutter epub-writer

dart-epub's People

Contributors

alexmeuer avatar jarontai avatar mostafaayesh avatar orthros avatar paulswith avatar renggli avatar shadowjonathan avatar timekone avatar vblago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart-epub's Issues

Mismatched hashcodes

The following code will print true false:

  var reference = new EpubBook();
  reference
    ..Author = "orthros"
    ..AuthorList = ["orthros"]
    ..Chapters = [new EpubChapter()]
    ..Content = new EpubContent()
    ..CoverImage = image.Image(100, 100)
    ..Schema = new EpubSchema()
    ..Title = "A Dissertation on Epubs";

  EpubBook testBook;
    testBook = new EpubBook();
    testBook
      ..Author = "orthros"
      ..AuthorList = ["orthros"]
      ..Chapters = [new EpubChapter()]
      ..Content = new EpubContent()
      ..CoverImage = image.Image(100, 100)
      ..Schema = new EpubSchema()
      ..Title = "A Dissertation on Epubs";

  print(reference == testBook);
  print(reference.hashCode == testBook.hashCode);

This bug is present in numerous classes with List fields.

Epub parsing error when href is a ralative path

navigation_reader.dart:

String tocFileEntryPath =
        ZipPathUtils.combine(contentDirectoryPath, tocManifestItem.Href);

zip_path_utils.dart:

static String combine(String directory, String fileName) { 
    if (directory == null || directory == "") {
      return fileName;
    } else {
      return directory + "/" + fileName;
    }
  }
}

If the tocManifestItem.Href is a ralative path such as "./toc.ncx",the method combine() will return wrong path like OEBPS/./toc.ncx,and error occurred.

Ralative path should be considered in method combine.

Thanks.

Failed decoding image

@orthros I'm trying to do exactly that, but I'm getting a decoding error. Can you point me in the right direction?

E/flutter (17553): [ERROR:flutter/lib/ui/painting/codec.cc(100)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
I/flutter (17553): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (17553): The following _Exception was thrown resolving an image codec:
I/flutter (17553): Exception: operation failed

Doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.7.3, on Microsoft Windows [Version 10.0.17134.285], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[√] Connected devices (1 available)

• No issues found!

Package epub has no versions that match >=1.2.0 <2.0.0

Hi,
I'm trying to play with this package but until now I get the following error when doing flutter packages get:

Package epub has no versions that match >=1.2.0 <2.0.0 derived from:
- EpubTestApp depends on version ^1.2.0

Any idea? Thanks a lot in advance!

Exception: Incorrect EPUB spine: TOC is missing

Hi,
Please can you check this epub book ? Year Five Maths: Operations on Numbers

The part of the code:

  _readEpubFile(String filePath) async {
    var targetFile = new io.File(filePath);
  List<int> bytes = await targetFile.readAsBytes();
  EpubBook epubBook = await EpubReader.readBook(bytes);
EpubContent bookContent = epubBook.Content;

Map<String, EpubTextContentFile> htmlFiles = bookContent.Html;
StringBuffer sb = StringBuffer();

 htmlFiles.values.forEach((EpubTextContentFile htmlFile) {
   String htmlContent = htmlFile.Content;
   sb.write(htmlContent);
 });

It's throwing an exception:

E/flutter ( 7117): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter ( 7117): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter ( 7117): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 7117): #18     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter ( 7117): #19     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter ( 7117): #20     _invoke1 (dart:ui/hooks.dart:142:13)
E/flutter ( 7117): #21     _dispatchPointerDataPacket (dart:ui/hooks.dart:99:5)

Thanks

EpubReader crashes when reading a book with the TOC referencing a file with unicode/utf8 characters

This is probably an archive fault, but best to start mentioning it here, as it also affects this package:

  for (var file in files) {
    if (verbose) print("Getting file " + file.path);
    EpubBook book =
        await EpubReader.readBook(new File.fromUri(file.uri).readAsBytesSync());
    if (verbose) print("  " + book?.Title);
    ...
  }

Resulting (after a while) into the following throw:

Getting file D:/Google Drive/Books\Complete Turnabout - Nenilein.epub
Unhandled exception:
Exception: EPUB parsing error: file OEBPS/Mentor-and-Protégé.html not found in archive.
#0      EpubContentFileRef.getContentFileEntry (package:epub/src/ref_entities/epub_content_file_ref.dart:47:7)
#1      EpubContentFileRef.getContentStream (package:epub/src/ref_entities/epub_content_file_ref.dart:34:30)
#2      EpubContentFileRef.readContentAsText (package:epub/src/ref_entities/epub_content_file_ref.dart:28:31)
<asynchronous suspension>
#3      EpubReader.readTextContentFiles.<anonymous closure> (package:epub/src/epub_reader.dart:100:45)
<asynchronous suspension>
#4      Future.forEach.<anonymous closure> (dart:async/future.dart:484)
#5      Future.doWhile.<anonymous closure> (dart:async/future.dart:526)
#6      _RootZone.runUnaryGuarded (dart:async/zone.dart:1316)
#7      _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1355)
#8      _RootZone.runUnary (dart:async/zone.dart:1381)
#9      _FutureListener.handleValue (dart:async/future_impl.dart:129)
#10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:638)
#11     Future._propagateToListeners (dart:async/future_impl.dart:667)
#12     Future._complete (dart:async/future_impl.dart:472)
#13     _SyncCompleter.complete (dart:async/future_impl.dart:51)
#14     _completeOnAsyncReturn (dart:async-patch/dart:async/async_patch.dart:292)
#15     EpubReader.readTextContentFiles.<anonymous closure> (package:epub/src/epub_reader.dart:102:5)
#16     _RootZone.runUnary (dart:async/zone.dart:1381)
#17     _FutureListener.handleValue (dart:async/future_impl.dart:129)
#18     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:638)
#19     Future._propagateToListeners (dart:async/future_impl.dart:667)
#20     Future._complete (dart:async/future_impl.dart:472)
#21     _SyncCompleter.complete (dart:async/future_impl.dart:51)
#22     _completeOnAsyncReturn (dart:async-patch/dart:async/async_patch.dart:292)
#23     EpubContentFileRef.readContentAsText (package:epub/src/ref_entities/epub_content_file_ref.dart:30:5)
#24     new Future.microtask.<anonymous closure> (dart:async/future.dart:200)
#25     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#26     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#27     _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:113)
#28     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:166)

Changing lib/src/ref_entities/epub_content_file_ref.dart:~40 to this:

ArchiveFile contentFileEntry = epubBookRef.EpubArchive().files.firstWhere(
            (ArchiveFile x) {print(x.name);return x.name == contentFilePath;},
        orElse: () => null);

Reveals that the archive files are named like this:

OEBPS/Miseries.html
OEBPS/First-Investigations.html
OEBPS/Mentor-and-Protégé.html
OEBPS/Mayas-Objection.html
OEBPS/Alone.html

Here is the epub file in question (zipped, as github doesnt accept .epub files)
Complete Turnabout - Nenilein.zip

It was downloaded from http://ficsave.xyz

update pubspec

Because xml2json >=4.2.1 depends on xml ^4.2.0 and epub 2.1.0 depends on xml >=2.6.0 <4.0.0, xml2json >=4.2.1 is incompatible with epub 2.1.0.
And because no versions of epub match >2.1.0 <3.0.0, xml2json >=4.2.1 is incompatible with epub ^2.1.0.

Create epub from folder

Could we support create epub from folder, we only description some meta data and toc nav, and the zip task will run on isolate.

Can't do flutter get packages

Getting this when I do flutter packages get

The current Dart SDK version is 2.0.0-dev.63.0.flutter-4c9689c1d2.

Because e_reader depends on epub >=2.0.0 which requires SDK version >=2.0.0 <3.0.0, version solving failed.

Seems to be related/similar to the other issue in this project. I also noticed there was a recent commit that may be resolving this issue.

Trouble with loading cover images.

I tried loading the cover image as per flutter app example, and the library seems to have trouble finding the cover image of the epub file even though it exists (confirmed via other apps and me looking at its meta data).

Here is the code :

Widget buildDocumentItem(epub.EpubBookRef book) {
    return Card(
        child: InkWell(
            splashColor: Colors.black.withAlpha(30),
            onTap: () {

            },
            child: Column(
                children: <Widget>[
                    FutureBuilder<epub.Image>(
                        future: book.readCover(),
                        builder: (context, snapshot) {
                            if (snapshot.hasData) {
                                return Image.memory(image.encodeJpg(snapshot.data));
                            } else if (snapshot.hasError) {
                                return Text("${snapshot.error}");
                            }

                            return Container();
                        }
                    ),
                    Text(book.Title),
                    Text(book.Author),
                ]
            ),
        ),
    );
}

Any idea?

Error when opening epub 3 file.

I'm having this error when calling, file.readAsBytes() in an Epub3 file..

E/flutter (28533): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: FormatException: Unexpected extension byte (at offset 139)

NNBD and more darty api

In dart, the convention is camelCase, final fields, and now, nnbd. The package needs an great migration. I did it at my github, but it is an humongous breaking change and contains 3 packages that i made and didnt publish to pub.dev. I tried to only migrate to nnbd but because the fields are set after object initialization, it proved to be rather chalenging. So as it was becoming an big breaking change with big consequences i ended up doing it my way.

About the file size

Hi, and thanks for sharing this dart package. Just a question, did you test it on files that have sizes > 2 mega bytes ?

I'm asking because if this is a memory friendly when the file size is big, maybe the app will crash.

Thanks

Using dart-epub in Flutter?

Sorry if I'm posting in the wrong section I did try contacting Colin awhile back via email but heard nothing back, I've also asked on StackOverflow.
Are there any examples showing how to use this inside a flutter application? Any guidance would be greatly appreciated.

Epub book read-write then read again => "EPUB parsing error: root file not found in archive."

I was using epub package just to see how it works. I read an epub book with
EpubBook epubBook = await EpubReader.readBook(bytes);

then i saved it without any changes then I read it again

var written = EpubWriter.writeBook(epubBook); var newBook = await EpubReader.readBook(written);

I got "EPUB parsing error: root file not found in archive." exception.
I investigated for a while and I found:

  • My epub book contains content.opf in the root of epubArchive, not in OEBPS/content.opf
  • while writing my epub book, _EpubWriter.container_file constant contains OEBPS/content.opf
  • As a result, adding the container file META-INF/container.xml, the OEBPS/content.opf reference was set while content.opf was on the root.
  • Subseguent searches throw an exception when I re-read saved epub book.

I think the following quick patch of EpubWriter can help and, perhaps, it's possible to apply an even better one.

static Archive _createArchive(EpubBook book) {
    var arch = Archive();

    final StringBuffer buffer = StringBuffer('<?xml version="1.0"?><container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"><rootfiles><rootfile full-path=')
      ..write('"')
      ..write(book.Schema.ContentDirectoryPath)
      ..write(book.Schema.ContentDirectoryPath.isEmpty ? 'content.opf' : '/content.opf'  )
      ..write('"')
      ..write(' media-type="application/oebps-package+xml"/></rootfiles></container>');
    final String _container_file = buffer.toString();


    // Add simple metadata
    arch.addFile(ArchiveFile.noCompress(
        "metadata", 20, convert.utf8.encode("application/epub+zip")));

    // Add Container file
    arch.addFile(ArchiveFile("META-INF/container.xml", _container_file.length,
        convert.utf8.encode(_container_file)));
...

reading epub file is slow and take a lot of time

It loads everything first into memory which takes a lot of time that way. this is a problem when the epub file gets larger
Another problem that it doesn't have pagination which is something necessary.

something else is that you can't load images with HTML.
how to load images within the pages? it gives HTML and images separately

EpubByteContentFileRef.readContent() to return Future<Uint8List>

With an older version of flutter 0.5.1 and epub 1.3.2 I could load an image in a the Image widget with EpubByteContentFileRef.readContent() and Image.memory(...). But with the latest flutter dev version 0.5.8 and epub 2.0.2 there is an exception: type 'List<int>' is not a subtype of type 'Uint8List'

parse fail when 'contentFileName' contain urlencoded coding

I parse my epub book, encounter the below error tips

Exception: Incorrect EPUB manifest: item with href = "Qian%20Yan%20.html" is missing.

I found that inside bookRef.Content.Html existing a similar key is 'Qian Yan .html', but here the contentFileName was being urlencoded;

image

Add contentFileName = Uri.decodeFull(contentFileName); to chapter_reader.dart:31 is working for me.

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.