-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
ReadiumAdapterMinizip
library (#548)
- Loading branch information
1 parent
8d9844f
commit d805e4e
Showing
18 changed files
with
688 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Copyright 2025 Readium Foundation. All rights reserved. | ||
// Use of this source code is governed by the BSD-style license | ||
// available in the top-level LICENSE file of the project. | ||
// | ||
|
||
import Foundation | ||
import ReadiumShared | ||
|
||
/// An ``ArchiveOpener`` able to open ZIP archives using Minizip. | ||
/// | ||
/// Compared to the default ZIPFoundation implementation shipped with | ||
/// ReadiumShared, the ``MinizipArchiveOpener``: | ||
/// | ||
/// - Does not support HTTP streaming of ZIP archives. | ||
/// - Has better performance when reading an LCP-protected package containing | ||
/// large deflated ZIP entries (instead of stored). | ||
public final class MinizipArchiveOpener: ArchiveOpener { | ||
public init() {} | ||
|
||
public func open(resource: any Resource, format: Format) async -> Result<ContainerAsset, ArchiveOpenError> { | ||
guard | ||
format.conformsTo(.zip), | ||
let file = resource.sourceURL?.fileURL | ||
else { | ||
return .failure(.formatNotSupported(format)) | ||
} | ||
|
||
return await MinizipContainer.make(file: file) | ||
.mapError { | ||
switch $0 { | ||
case .notAZIP: | ||
return .formatNotSupported(format) | ||
case let .reading(error): | ||
return .reading(error) | ||
} | ||
} | ||
.map { ContainerAsset(container: $0, format: format) } | ||
} | ||
|
||
public func sniffOpen(resource: any Resource) async -> Result<ContainerAsset, ArchiveSniffOpenError> { | ||
guard let file = resource.sourceURL?.fileURL else { | ||
return .failure(.formatNotRecognized) | ||
} | ||
|
||
return await MinizipContainer.make(file: file) | ||
.mapError { | ||
switch $0 { | ||
case .notAZIP: | ||
return .formatNotRecognized | ||
case let .reading(error): | ||
return .reading(error) | ||
} | ||
} | ||
.map { | ||
ContainerAsset( | ||
container: $0, | ||
format: Format( | ||
specifications: .zip, | ||
mediaType: .zip, | ||
fileExtension: "zip" | ||
) | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.