Skip to content

Commit

Permalink
remove another force unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 18, 2024
1 parent 5cecd1d commit 9c806cd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/XMTPiOS/EncodedContentCompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ public enum EncodedContentCompression {
_ data: Data, using algorithm: compression_algorithm
) -> Data? {
let destinationBuffer = UnsafeMutablePointer<UInt8>.allocate(
capacity: data.count)
capacity: data.count
)
defer { destinationBuffer.deallocate() }

let compressedSize = data.withUnsafeBytes { sourceBuffer in
compression_encode_buffer(
let compressedSize = data.withUnsafeBytes { sourceBuffer -> Int in
guard let sourcePointer = sourceBuffer.baseAddress?.assumingMemoryBound(to: UInt8.self) else {
return 0 // Return 0 to indicate failure
}
return compression_encode_buffer(
destinationBuffer, data.count,
sourceBuffer.baseAddress!.assumingMemoryBound(to: UInt8.self),
data.count, nil, algorithm)
sourcePointer, data.count, nil, algorithm
)
}

guard compressedSize > 0 else { return nil }
Expand Down

0 comments on commit 9c806cd

Please sign in to comment.