Skip to content

Commit 7cf8c50

Browse files
Merge pull request #217 from memoto/master
Encode log data to ascii string using c string pointer
2 parents 251e44b + 987ee78 commit 7cf8c50

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/XCLogParser/loglocation/LogLoader.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ public struct LogLoader {
2626
do {
2727
let data = try Data(contentsOf: url)
2828
let unzipped = try data.gunzipped()
29-
guard let contents = String(data: unzipped, encoding: .ascii) else {
29+
let string: String? = unzipped.withUnsafeBytes { pointer in
30+
guard let charPointer = pointer
31+
.assumingMemoryBound(to: CChar.self)
32+
.baseAddress
33+
else {
34+
return nil
35+
}
36+
37+
return String(cString: charPointer, encoding: .ascii)
38+
}
39+
guard let contents = string else {
3040
throw LogError.readingFile(url.path)
3141
}
3242
return contents

0 commit comments

Comments
 (0)