ReadViewSDK/Sources/RDEpubReaderView/EPUBCore/RDEPUBResourceDataProvider.swift
shenlei d7fcda345d refactor: rename RDReaderView -> RDEpubReaderView, update pod config and docs
- Rename source module from RDReaderView to RDEpubReaderView
- Move all source files from Sources/RDReaderView/ to Sources/RDEpubReaderView/
- Update podspec: RDReaderView.podspec -> RDEpubReaderView.podspec
- Update Podfile, demo project, and CocoaPods config for new pod name
- Delete old RDReaderView pod support files from ReadViewDemo/Pods
- Add new RDEpubReaderView pod support files
- Update documentation (API ref, architecture, UML, conventions, etc.)
- Add FixedLayoutRotationTests
- Update .gitignore: exclude .DS_Store, manual unpack backups, _ssoft-output
2026-07-10 19:44:53 +09:00

64 lines
2.7 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
/// EPUB
///
/// 宿 App EPUB
/// SDK HTML CSS provider
/// provider nil SDK 退
///
///
/// 宿SDK
///
/// / 线
/// I/O
public protocol RDEPUBResourceDataProvider: AnyObject {
///
/// - Parameter fileURL:
/// - Returns: nil SDK
func resourceData(at fileURL: URL) -> Data?
}
/// 访
///
/// DTCoreText `<img>` parser
/// provider parser
/// `RDEPUBDecryptingImageAttachment` provider
enum RDEPUBResourceAccessRegistry {
private struct WeakParserBox {
weak var parser: RDEPUBParser?
}
private static let lock = NSLock()
private static var boxes: [WeakParserBox] = []
/// provider parser
static func register(_ parser: RDEPUBParser) {
lock.lock()
defer { lock.unlock() }
boxes.removeAll { $0.parser == nil || $0.parser === parser }
boxes.append(WeakParserBox(parser: parser))
#if canImport(DTCoreText)
RDEPUBDecryptingImageAttachment.registerTagClassIfNeeded()
#endif
}
/// provider
/// parser
static func providedResourceData(at fileURL: URL) -> Data? {
let targetPath = fileURL.resolvingSymlinksInPath().standardizedFileURL.path
lock.lock()
let parsers = boxes.compactMap(\.parser)
lock.unlock()
for parser in parsers {
guard let rootURL = parser.extractionRootURL else { continue }
let rootPath = rootURL.resolvingSymlinksInPath().standardizedFileURL.path
guard targetPath.hasPrefix(rootPath + "/") else { continue }
return parser.providedResourceData(at: fileURL)
}
return nil
}
}