Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Dec 11, 2024
1 parent 6d44cd5 commit 68d0a03
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 44 deletions.
12 changes: 5 additions & 7 deletions Sources/Shared/Toolkit/ZIP/ZIPFoundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import ReadiumZIPFoundation

/// An ``ArchiveOpener`` able to open ZIP archives using ZIPFoundation.
public final class ZIPFoundationArchiveOpener: ArchiveOpener {

public init() {}

public func open(resource: any Resource, format: Format) async -> Result<ContainerAsset, ArchiveOpenError> {
guard
format.conformsTo(.zip),
Expand Down Expand Up @@ -152,14 +151,13 @@ private actor ZIPFoundationResource: Resource, Loggable {
}

func stream(range: Range<UInt64>?, consume: @escaping (Data) -> Void) async -> ReadResult<Void> {
if range != nil {
}
if range != nil {}

return await archive().flatMap { archive in
guard let entry = archive[entryPath] else {
return .failure(.decoding("No entry found in the ZIP at \(entryPath)"))
}

do {
if let range = range {
try archive.extractRange(range, of: entry) { data in
Expand All @@ -176,12 +174,12 @@ private actor ZIPFoundationResource: Resource, Loggable {
}
}
}

private var _archive: ReadResult<ReadiumZIPFoundation.Archive>?
private func archive() async -> ReadResult<ReadiumZIPFoundation.Archive> {
if _archive == nil {
do {
_archive = .success(try ReadiumZIPFoundation.Archive(url: file.url, accessMode: .read, pathEncoding: nil))
_archive = try .success(ReadiumZIPFoundation.Archive(url: file.url, accessMode: .read))
} catch {
_archive = .failure(.decoding(error))
}
Expand Down
1 change: 1 addition & 0 deletions Support/Carthage/.xcodegen
Original file line number Diff line number Diff line change
Expand Up @@ -13963,6 +13963,7 @@
../../Sources/Shared/Toolkit/XML/XML.swift
../../Sources/Shared/Toolkit/ZIP
../../Sources/Shared/Toolkit/ZIP/ZIPArchiveOpener.swift
../../Sources/Shared/Toolkit/ZIP/ZIPFoundation.swift
../../Sources/Streamer
../../Sources/Streamer/Assets
../../Sources/Streamer/Assets/fonts
Expand Down
4 changes: 4 additions & 0 deletions Support/Carthage/Readium.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
66018235ED40B89D27EE9F33 /* Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FAAD26EE52713DB9F103610 /* Group.swift */; };
66A251DA78C53384E94F169F /* PublicationServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D87AB6FB1B213E6269736B /* PublicationServer.swift */; };
6719F981514309A65D206A85 /* LCPAcquisition.swift in Sources */ = {isa = PBXBuildFile; fileRef = F622773881411FB8BE686B9F /* LCPAcquisition.swift */; };
6724EAA0D931CF252E5FAEDF /* ZIPFoundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59624A8738EB3A791CEF8E4C /* ZIPFoundation.swift */; };
674BEEF110667C3051296E9B /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F3481F848A616A9A825A4BD /* Double.swift */; };
67F1C7C3D434D2AA542376E3 /* PublicationParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F609C27F073E40D662CFE093 /* PublicationParser.swift */; };
682DFC1AF2BD7CAE0862B331 /* CryptoSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E37F94C388A86CB8A34812A5 /* CryptoSwift.xcframework */; };
Expand Down Expand Up @@ -611,6 +612,7 @@
567C115FF0939F69AD83AE82 /* UserRights.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRights.swift; sourceTree = "<group>"; };
56C489452239BF85F4D14E95 /* PublicationMediaLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicationMediaLoader.swift; sourceTree = "<group>"; };
57338C29681D4872D425AB81 /* UInt64.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInt64.swift; sourceTree = "<group>"; };
59624A8738EB3A791CEF8E4C /* ZIPFoundation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZIPFoundation.swift; sourceTree = "<group>"; };
5A85DB4931BA5D965042CC6F /* CompositePublicationParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompositePublicationParser.swift; sourceTree = "<group>"; };
5BC6AE42A31D77B548CB0BB4 /* Observable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observable.swift; sourceTree = "<group>"; };
5E788FD34BE635B4B80C18A6 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1105,6 +1107,7 @@
isa = PBXGroup;
children = (
C51C74A5990A3BA93B3DC587 /* ZIPArchiveOpener.swift */,
59624A8738EB3A791CEF8E4C /* ZIPFoundation.swift */,
);
path = ZIP;
sourceTree = "<group>";
Expand Down Expand Up @@ -2664,6 +2667,7 @@
5591563FD08A956B80C37716 /* XMLFormatSniffer.swift in Sources */,
BBF5AAEEE90BD88D58191DA3 /* ZIPArchiveOpener.swift in Sources */,
B49522888052E9F41D0DD013 /* ZIPFormatSniffer.swift in Sources */,
6724EAA0D931CF252E5FAEDF /* ZIPFoundation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 0 additions & 1 deletion TestApp/Sources/App/Readium.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import Foundation
import ReadiumAdapterGCDWebServer
import ReadiumAdapterZIPFoundation
import ReadiumNavigator
import ReadiumShared
import ReadiumStreamer
Expand Down
1 change: 0 additions & 1 deletion Tests/Adapters/ZIPFoundationTests/Fixtures

This file was deleted.

29 changes: 0 additions & 29 deletions Tests/Adapters/ZIPFoundationTests/Fixtures.swift

This file was deleted.

11 changes: 5 additions & 6 deletions Tests/SharedTests/Toolkit/Archive/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import XCTest
private let fixtures = Fixtures(path: "Archive")

class ZIPFoundationTests: XCTestCase {

private func container(for filename: String) async throws -> Container {
try await ZIPFoundationContainer.make(file: fixtures.url(for: filename)).get()
}

func testOpenSuccess() async throws {
_ = try await container(for: "test.zip")
}
Expand Down Expand Up @@ -107,9 +106,9 @@ class ZIPFoundationTests: XCTestCase {
" ZIP.\n"
)
}

func testRandomCompressedRead() async throws {
for _ in 0..<100 {
for _ in 0 ..< 100 {
let container = try await container(for: "test.zip")
let entry = try XCTUnwrap(container[AnyURL(path: "A folder/wasteland-cover.jpg")!])
let length: UInt64 = 103_477
Expand All @@ -119,9 +118,9 @@ class ZIPFoundationTests: XCTestCase {
_ = try await entry.read(range: range).get()
}
}

func testRandomStoredRead() async throws {
for _ in 0..<100 {
for _ in 0 ..< 100 {
let container = try await container(for: "test.zip")
let entry = try XCTUnwrap(container[AnyURL(path: "uncompressed.jpg")!])
let length: UInt64 = 279_551
Expand Down

0 comments on commit 68d0a03

Please sign in to comment.