Skip to content

Commit

Permalink
Merge pull request #217 from memoto/master
Browse files Browse the repository at this point in the history
Encode log data to ascii string using c string pointer
  • Loading branch information
aleksandergrzyb authored Dec 23, 2024
2 parents 251e44b + 987ee78 commit 7cf8c50
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/XCLogParser/loglocation/LogLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ public struct LogLoader {
do {
let data = try Data(contentsOf: url)
let unzipped = try data.gunzipped()
guard let contents = String(data: unzipped, encoding: .ascii) else {
let string: String? = unzipped.withUnsafeBytes { pointer in
guard let charPointer = pointer
.assumingMemoryBound(to: CChar.self)
.baseAddress
else {
return nil
}

return String(cString: charPointer, encoding: .ascii)
}
guard let contents = string else {
throw LogError.readingFile(url.path)
}
return contents
Expand Down

0 comments on commit 7cf8c50

Please sign in to comment.