From efb863a2af198a21c7dcf6f909ed265d1f28e98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= <mickael.menu@gmail.com> Date: Tue, 28 Jan 2025 17:41:18 +0100 Subject: [PATCH] Lint --- .../Adapters/Minizip/MinizipArchiveOpener.swift | 3 +-- Sources/Adapters/Minizip/MinizipContainer.swift | 2 +- Sources/Internal/Extensions/Result.swift | 1 - Sources/Internal/Extensions/UInt64.swift | 7 +++---- .../Toolkit/Data/Resource/BufferingResource.swift | 14 +++++++------- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Sources/Adapters/Minizip/MinizipArchiveOpener.swift b/Sources/Adapters/Minizip/MinizipArchiveOpener.swift index bd8a56b86..33d1116b8 100644 --- a/Sources/Adapters/Minizip/MinizipArchiveOpener.swift +++ b/Sources/Adapters/Minizip/MinizipArchiveOpener.swift @@ -16,9 +16,8 @@ import ReadiumShared /// - 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), diff --git a/Sources/Adapters/Minizip/MinizipContainer.swift b/Sources/Adapters/Minizip/MinizipContainer.swift index 0314707c1..fa2d0fd86 100644 --- a/Sources/Adapters/Minizip/MinizipContainer.swift +++ b/Sources/Adapters/Minizip/MinizipContainer.swift @@ -5,8 +5,8 @@ // import Foundation -import ReadiumShared import Minizip +import ReadiumShared /// A ZIP ``Container`` using the Minizip library. final class MinizipContainer: Container, Loggable { diff --git a/Sources/Internal/Extensions/Result.swift b/Sources/Internal/Extensions/Result.swift index 12a2ce7e2..d02eb5ef4 100644 --- a/Sources/Internal/Extensions/Result.swift +++ b/Sources/Internal/Extensions/Result.swift @@ -7,7 +7,6 @@ import Foundation public extension Result { - func getOrNil() -> Success? { try? get() } diff --git a/Sources/Internal/Extensions/UInt64.swift b/Sources/Internal/Extensions/UInt64.swift index 6a90243a2..aa8b17082 100644 --- a/Sources/Internal/Extensions/UInt64.swift +++ b/Sources/Internal/Extensions/UInt64.swift @@ -1,8 +1,7 @@ // -// UInt64.swift -// Readium -// -// Created by Mickaƫl on 1/28/25. +// 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. // public extension UInt64 { diff --git a/Sources/Shared/Toolkit/Data/Resource/BufferingResource.swift b/Sources/Shared/Toolkit/Data/Resource/BufferingResource.swift index 286bdf680..4833dcf1c 100644 --- a/Sources/Shared/Toolkit/Data/Resource/BufferingResource.swift +++ b/Sources/Shared/Toolkit/Data/Resource/BufferingResource.swift @@ -90,19 +90,19 @@ public actor BufferingResource: Resource, Loggable { } let adjustedRange = adjustedStart ..< adjustedEnd log(.trace, "Requested \(requestedRange) (\(requestedRange.count) bytes), adjusted to \(adjustedRange) (\(adjustedRange.count) bytes) of resource with length \(length)") - + var data = Data() - + // Range that will need to be read from the original resource. var readRange = adjustedRange - + // Checks if the beginning of the range to read is already buffered. // This is an optimization particularly useful with LCP, where we need // to go backward for every read to get the previous block of data. if readRange.lowerBound < buffer.range.upperBound, readRange.upperBound > buffer.range.upperBound, - let dataPrefix = buffer.get(range: readRange.lowerBound..<buffer.range.upperBound) + let dataPrefix = buffer.get(range: readRange.lowerBound ..< buffer.range.upperBound) { log(.trace, "Found \(dataPrefix.count) bytes to reuse at the end of the buffer") data.append(dataPrefix) @@ -110,7 +110,7 @@ public actor BufferingResource: Resource, Loggable { } log(.trace, "Will read \(readRange) (\(readRange.count) bytes)") - + // Fallback on reading the requested range from the original resource. return await resource.read(range: readRange) .flatMap { readData in @@ -130,9 +130,9 @@ public actor BufferingResource: Resource, Loggable { let maxSize: Int private var data: Data = .init() private var startOffset: UInt64 = 0 - + var range: Range<UInt64> { - startOffset..<(startOffset + UInt64(data.count)) + startOffset ..< (startOffset + UInt64(data.count)) } init(maxSize: Int) {