Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Jan 28, 2025
1 parent 1d02f00 commit efb863a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Sources/Adapters/Minizip/MinizipArchiveOpener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion Sources/Adapters/Minizip/MinizipContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//

import Foundation
import ReadiumShared
import Minizip
import ReadiumShared

/// A ZIP ``Container`` using the Minizip library.
final class MinizipContainer: Container, Loggable {
Expand Down
1 change: 0 additions & 1 deletion Sources/Internal/Extensions/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import Foundation

public extension Result {

func getOrNil() -> Success? {
try? get()
}
Expand Down
7 changes: 3 additions & 4 deletions Sources/Internal/Extensions/UInt64.swift
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Shared/Toolkit/Data/Resource/BufferingResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ 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)
readRange = buffer.range.upperBound ..< readRange.upperBound
}

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
Expand All @@ -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) {
Expand Down

0 comments on commit efb863a

Please sign in to comment.