Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Add unzip path to title and author name getters (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
revolter authored and hebertialmeida committed Jan 18, 2018
1 parent 59a1350 commit 6250c35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 11 additions & 7 deletions Source/EPUBCore/FREpubParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {

/// Parse the book title from an epub file.
///
/// - Parameter epubPath: Epub path on the disk
/// - Parameters:
/// - epubPath: Epub path on the disk.
/// - unzipPath: Path to unzip the compressed pub.
/// - Returns: The book title
/// - Throws: `FolioReaderError`
func parseTitle(_ epubPath: String) throws -> String {
guard let book = try? readEpub(epubPath: epubPath, removeEpub: false), let title = book.title else {
func parseTitle(_ epubPath: String, unzipPath: String? = nil) throws -> String {
guard let book = try? readEpub(epubPath: epubPath, removeEpub: false, unzipPath: unzipPath), let title = book.title else {
throw FolioReaderError.titleNotAvailable
}
return title
Expand All @@ -56,11 +58,13 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {

/// Parse the book Author name from an epub file.
///
/// - Parameter epubPath: Epub path on the disk
/// - Returns: Author name
/// - Parameters:
/// - epubPath: Epub path on the disk.
/// - unzipPath: Path to unzip the compressed pub.
/// - Returns: The author name
/// - Throws: `FolioReaderError`
func parseAuthorName(_ epubPath: String) throws -> String {
guard let book = try? readEpub(epubPath: epubPath, removeEpub: false), let authorName = book.authorName else {
func parseAuthorName(_ epubPath: String, unzipPath: String? = nil) throws -> String {
guard let book = try? readEpub(epubPath: epubPath, removeEpub: false, unzipPath: unzipPath), let authorName = book.authorName else {
throw FolioReaderError.authorNameNotAvailable
}
return authorName
Expand Down
10 changes: 5 additions & 5 deletions Source/FolioReaderKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ extension FolioReader {
}
}

// MARK: - Image Cover
// MARK: - Metadata

extension FolioReader {

Expand All @@ -322,12 +322,12 @@ extension FolioReader {
return try FREpubParser().parseCoverImage(epubPath, unzipPath: unzipPath)
}

open class func getTitle(_ epubPath: String) throws -> String? {
return try FREpubParser().parseTitle(epubPath)
open class func getTitle(_ epubPath: String, unzipPath: String? = nil) throws -> String? {
return try FREpubParser().parseTitle(epubPath, unzipPath: unzipPath)
}

open class func getAuthorName(_ epubPath: String) throws-> String? {
return try FREpubParser().parseAuthorName(epubPath)
open class func getAuthorName(_ epubPath: String, unzipPath: String? = nil) throws-> String? {
return try FREpubParser().parseAuthorName(epubPath, unzipPath: unzipPath)
}
}

Expand Down

0 comments on commit 6250c35

Please sign in to comment.