https://github.com/cxa/fpub
Library for reading EPUB file format built on top of .NET Standard 2.0 and F#.
https://github.com/cxa/fpub
Last synced: about 1 year ago
JSON representation
Library for reading EPUB file format built on top of .NET Standard 2.0 and F#.
- Host: GitHub
- URL: https://github.com/cxa/fpub
- Owner: cxa
- License: mit
- Created: 2018-01-02T16:58:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-06T07:22:26.000Z (over 2 years ago)
- Last Synced: 2025-04-25T14:50:36.759Z (about 1 year ago)
- Language: F#
- Homepage:
- Size: 323 KB
- Stars: 19
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fpub
Library for reading EPUB file format built on top of .NET Standard 2.0 and F#.
Safe, simple and extendable.
Available on NuGet:
## Simple things should be simple
```fsharp
module Container = begin
type T
// Open EPUB
val withStream : stream:System.IO.Stream -> Result
val withFile : file:string -> Result
// Get resource from EPUB with path
val getResource : T -> path:string -> Result
// Get EPUB package document
val getPackagePaths : container:T -> Result,exn>
val getDefaultPackage : container:T -> Result
// Get EPUB navigation document
val getNav : container:T -> Result
// Get EPUB 2 NCX document (until navigation document is missing)
val getNcx : container:T -> Result
end
// Read Package Document
module Package = begin
module Metadata = begin
type T
val getElement : T -> Element.T
val getUniqueIdentifier : T -> Result
val getReleaseIdentifier : metadata:T -> Result
val getAllIdentifiers : T -> Result,exn>
val getSchemeIdentifiers : T -> Result,exn>
val getTitle : T -> Result
val getLanguage : T -> Result
val getCreators : T -> Result,exn>
val getContributors : T -> Result,exn>
val getDate : T -> Result
end
module Manifest = begin
type T
val getElement : T -> Element.T
module Item = begin
type T
val getElement : T -> Element.T
val getAttribute : attribute:string -> T -> Result
val getId : item:T -> Result
val getHref : item:T -> Result
val getMediaType : item:T -> Result
val getResourcePath : item:T -> Result
end
val getItems : T -> Result,exn>
val getItemById : id:string -> T -> Result
val getNavItem : T -> Result
val getCoverImageItem : item:T -> Result
end
module Spine = begin
type T
val getElement : T -> Element.T
module ItemRef = begin
type T
val getElement : T -> Element.T
val getId : T -> Result
val getLinear : T -> Result
val getProperties : T -> Result
val getIdref : T -> Result
val getManifestItem :
itemRef:T -> element:Manifest.T -> Result
end
module PageProgressionDirection = begin
type T =
| Ltr
| Rtl
| Default
end
val getPageProgressionDirection : T -> PageProgressionDirection.T
val getItemRefs : T -> Result,exn>
end
type T
val withFile : uri:string -> pkgDir:string -> Result
val withStream : stream:System.IO.Stream -> pkgDir:string -> Result
val getElement : T -> Element.T
val getVersion : T -> Result
val getUniqueIdentifier : T -> Result
val getMetadata : T -> Result
val getManifest : T -> Result
val getSpine : T -> Result
val getNavDocPath : T -> Result
val getNcxPath : package:T -> Result
end
// Navigating
type TocItem = // Table of contents item
{title: string;
resourcePath: string option;
subitems: TocItem array;}
// Use EPUB3 navigation document
module Nav = begin
module Toc = begin
type T
val getHeadingTitle : T -> Result
val getItems : T -> TocItem []
end
module Landmarks = begin
type Item =
{title: string;
type: string;
resourcePath: string;
subitems: Item array;}
type T
val getHeadingTitle : T -> Result
val getItems : T -> Item []
end
module PageList = begin
type T
val getHeadingTitle : T -> Result
val getPages : T -> Map
end
type T
val withFile : uri:string -> docDir:string -> Result
val withStream : stream:System.IO.Stream -> docDir:string -> Result
val getElement : T -> Element.T
val getToc : T -> Result
val getLandmarks : T -> Result
val getPageList : T -> Result
end
// Use EPUB2 Ncx when EPUB3 navigation documen is missing
module Ncx = begin
module Toc = begin
type T
val getItems : T -> TocItem []
end
module PageList = begin
type T
val getPages : T -> Map
end
type T
val withFile : uri:string -> docDir:string -> Result
val withStream : stream:System.IO.Stream -> docDir:string -> Result
val getElement : T -> Element.T
val getToc : T -> Result
val getPageList : T -> Result
end
```
## Complex things should be possible
`Package`, `Nav`, `Ncx` and their submodules are abstracted in `Element.T`, which is an XML Element. Using `Element` to retrieve any information you needed.
```fsharp
module Element = begin
type T
val getValue : T -> string
val getAttribute : name:string -> T -> Result
val eval : xpath:string -> T -> Result
val evalToString : xpath:string -> element:T -> Result
val evalToDouble : xpath:string -> element:T -> Result
val evalToBoolean : xpath:string -> element:T -> Result
val evalToElements : xpath:string -> element:T -> Result,exn>
val getFirstElement : xpath:string -> T -> Result
val getAllElements : xpath:string -> T -> Result,exn>
end
```
## License
MIT
## Author
- Blog: [realazy.com](https://realazy.com) (Chinese)
- Github: [@cxa](https://github.com/cxa)
- X: [@\_realazy](https://x.com/_realazy) (Chinese mainly)