From db5735b8b50a752f0fcfac3463f94910a53f9b90 Mon Sep 17 00:00:00 2001 From: Uriel Hernandez Date: Mon, 16 Dec 2024 16:36:50 -0600 Subject: [PATCH 1/2] Updating ascii parsing --- Sources/XCLogParser/loglocation/LogLoader.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/XCLogParser/loglocation/LogLoader.swift b/Sources/XCLogParser/loglocation/LogLoader.swift index 4a39b88..5bc66e4 100644 --- a/Sources/XCLogParser/loglocation/LogLoader.swift +++ b/Sources/XCLogParser/loglocation/LogLoader.swift @@ -26,7 +26,18 @@ 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 From ef1f0e5f4af05e1a4e22b8d8ea65628ab99913b6 Mon Sep 17 00:00:00 2001 From: Uriel Hernandez Date: Mon, 16 Dec 2024 16:43:24 -0600 Subject: [PATCH 2/2] Fixing swiftlint --- Sources/XCLogParser/loglocation/LogLoader.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/XCLogParser/loglocation/LogLoader.swift b/Sources/XCLogParser/loglocation/LogLoader.swift index 5bc66e4..c7bfcd3 100644 --- a/Sources/XCLogParser/loglocation/LogLoader.swift +++ b/Sources/XCLogParser/loglocation/LogLoader.swift @@ -33,10 +33,10 @@ public struct LogLoader { else { return nil } - + return String(cString: charPointer, encoding: .ascii) } - + guard let contents = string else { throw LogError.readingFile(url.path) }