Skip to content

Commit

Permalink
Address swiftlint warnings + misc. comment changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichan Yoo committed Jan 13, 2025
1 parent 82945a7 commit ef272e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public struct FlexibleChecksumsRequestMiddleware<OperationStackInput, OperationS
}

var checksumHashFunction: ChecksumAlgorithm
if let checksumAlgorithm { // If checksum algorithm to use was configured via checksum algorithm input member by the user
if let checksumAlgorithm {
// If checksum algorithm to use was configured via checksum algorithm input member by the user
if let hashFunction = ChecksumAlgorithm.from(string: checksumAlgorithm) {
// If user chose a supported algorithm, continue
checksumHashFunction = hashFunction
Expand Down Expand Up @@ -117,18 +118,21 @@ public struct FlexibleChecksumsRequestMiddleware<OperationStackInput, OperationS
// If not eligible for chunked streaming, calculate and add checksum to request header now instead of as a trailing header.
let streamBytes: Data?
if stream.isSeekable {
let currentPosition = stream.position // Need to save current position to reset stream position after reading
// Need to save current position to reset stream position after reading
let currentPosition = stream.position
try stream.seek(toOffset: 0) // Explicit seek to beginning for correct behavior of FileHandle
streamBytes = try stream.readToEnd()
try stream.seek(toOffset: currentPosition) // Reset stream position to where it was before reading it for checksum calculation
// Reset stream position to where it was before reading it for checksum calculation
try stream.seek(toOffset: currentPosition)
} else {
streamBytes = try await stream.readToEndAsync()
builder.withBody(.data(streamBytes)) // Reset request body with streamBytes to "refill" it
}
try await calculateAndAddChecksumHeader(data: streamBytes)
}
case .noStream:
break // Unreachable block, but it's here for exhaustive switch case
// Unreachable block since we return early if .noStream, but it's here for exhaustive switch case
break
}

func calculateAndAddChecksumHeader(data: Data?) async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public struct FlexibleChecksumsResponseMiddleware<OperationStackInput, Operation

let checksumHeaderIsPresent = priorityList.first {
response.headers.value(for: "x-amz-checksum-\($0)") != nil &&
// When retrieving an object uploaded usingn mutipart upload (MPU) and flexible checksum,
// When retrieving an object uploaded using mutipart upload (MPU) and flexible checksum,
// S3 may return the checksum for the whole object (full object checksum)
// or the checksum of checksums (composite checksum).
// Composite checksums end in "-#" where # is an integer between 1 and 10000, indicating number of parts the object
// was original uploaded in.
// was originally uploaded in.
// The composite checksum should be ignored.
!isCompositeChecksum(response.headers.value(for: "x-amz-checksum-\($0)")!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FlexibleChecksumsRequestIntegration : SwiftIntegration {
*/
val useFlexibleChecksum = httpChecksumTrait != null && (
(
(httpChecksumTrait.requestAlgorithmMember?.orElse(null) != null) &&
(httpChecksumTrait.requestAlgorithmMember?.isPresent ?: false) &&
(input?.memberNames?.any { it == httpChecksumTrait.requestAlgorithmMember.get() } == true)
) || (httpChecksumTrait.isRequestChecksumRequired)
)
Expand Down

0 comments on commit ef272e7

Please sign in to comment.