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

Add unzip path to title and author name getters #303

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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