Skip to content

Commit 08b0ac8

Browse files
committed
fix: linux
1 parent c532025 commit 08b0ac8

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Sources/BinaryDependencyManager/DepeneciesResolverRunner.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,35 @@ struct DependenciesResolverRunner {
208208
}
209209

210210
private func calculateChecksum(path: String) throws -> String {
211-
let handle = try FileHandle(forReadingFrom: URL(fileURLWithPath: path))
212-
var hasher = SHA256()
211+
// Read the file in chunks to avoid RAM issues
212+
213+
let handle: FileHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: path))
214+
var hasher: SHA256 = SHA256()
215+
216+
#if os(macOS)
217+
213218
while autoreleasepool(invoking: {
214219
let nextChunk = handle.readData(ofLength: 1024 * 1024)
215220
guard !nextChunk.isEmpty else { return false }
216221
hasher.update(data: nextChunk)
217222
return true
218223
}) {}
219-
let digest = hasher.finalize()
224+
225+
#elseif os(Linux)
226+
227+
var eof: Bool = false
228+
var nextChunk: Data
229+
230+
while !eof {
231+
nextChunk = handle.readData(ofLength: 1024 * 1024)
232+
eof = nextChunk.isEmpty
233+
if !eof {
234+
hasher.update(data: nextChunk)
235+
}
236+
}
237+
238+
#endif
239+
let digest: SHA256.Digest = hasher.finalize()
220240
return digest.map { String(format: "%02hhx", $0) }.joined()
221241
}
222242
}

0 commit comments

Comments
 (0)