From 404ced8d4f6e97d15419e9b49d6c423a76474f1a Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Thu, 18 Jan 2018 23:55:35 +0200 Subject: [PATCH] Add unzip path to title and author name getters --- Source/EPUBCore/FREpubParser.swift | 18 +++++++++++------- Source/FolioReaderKit.swift | 10 +++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Source/EPUBCore/FREpubParser.swift b/Source/EPUBCore/FREpubParser.swift index 6dfc5b8a5..5ed2ef736 100755 --- a/Source/EPUBCore/FREpubParser.swift +++ b/Source/EPUBCore/FREpubParser.swift @@ -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 @@ -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 diff --git a/Source/FolioReaderKit.swift b/Source/FolioReaderKit.swift index bab91a51d..cf77a478c 100755 --- a/Source/FolioReaderKit.swift +++ b/Source/FolioReaderKit.swift @@ -308,7 +308,7 @@ extension FolioReader { } } -// MARK: - Image Cover +// MARK: - Metadata extension FolioReader { @@ -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) } }