自分でデータを完全に読み取るには、.epub ファイルを迅速に解凍する必要があります。ePub の出力を取得できればそれを解析する方法は知っていますが (Python で動作する例を作成しました)、SSZipArchive は明らかに .epub を解凍しません。ただし、ダミーの .zip ファイルでは問題なく動作します。.epub だけが問題です。私が知る限り、多くのオーバーヘッドを伴うObjective-cであなたのためにそれを行うプロジェクトに人々を単に向けることを超えて、SOで実際にこれを手動で行う方法を尋ねることに疑問の余地はありませんでした(私は理解していないか、必要としていません) )それは私がしなければならないことの目的を無効にします。以下は私の現在の試みです。問題の epub は、次のリンク (プロジェクト グーテンベルク) http://www.gutenberg.org/ebooks/158.epub.noimagesにあります。これを実行すると、print ステートメントは「true、true、true、false」を出力します (つまり、ファイルとパスはすべて存在しますが、解凍しません)。
import Foundation
class EpubExtractor: NSObject, SSZipArchiveDelegate {
init(fileName: String) {
fName = fileName
}
func getEpubInfo() {
var paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDir = paths[0]
let zipPath = documentsDir.stringByAppendingString("/MyZipFiles") // My folder name in document directory
let fileManager = NSFileManager.defaultManager()
let success1 = fileManager.fileExistsAtPath(zipPath) as Bool
if success1 == false {
print("no directory")
do {
try! fileManager.createDirectoryAtPath(zipPath, withIntermediateDirectories: true, attributes: nil)
}
}
let archivePath = zipPath.stringByAppendingString("/emma.epub") // Sample folder is going to zip with name Demo.zip
let success2 = fileManager.fileExistsAtPath(archivePath) as Bool
let destPath = zipPath.stringByAppendingString("/Hello")
let success3 = fileManager.fileExistsAtPath(destPath) as Bool
let worked = SSZipArchive.unzipFileAtPath(archivePath, toDestination: destPath, delegate:self)
print(success1, success2, success3, worked)
}
}
編集
以下は、Python で記述された概念コードの証明であり、まったく同じ epub を zip ファイルとして認識し、そのコンテナー コンテンツを読み取ることができます。
import zipfile
dir = "sampleData/epubs/"
fileName = "emma.epub"
print zipfile.is_zipfile(dir+fileName) # Check whether file is zip (this returns true, though in swift it fails)
zip = zipfile.ZipFile(dir+fileName)
txt = zip.read('META-INF/container.xml') # Print contents of container (this is what I need swift to be able to do)
print txt # This successfully prints the container content text