Fetcher.fetchViaFile(): use an mmap(2)-ed file, similarly to DiskV1 (#641)

* Fetcher.fetchViaFile(): use an mmap(2)-ed file, similarly to DiskV1

* No need to convert Data to Data
This commit is contained in:
Nikolay Edigaryev 2023-11-01 15:00:48 +04:00 committed by GitHub
parent c4c2bfeded
commit d8b69de52d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -35,12 +35,12 @@ class Fetcher {
//
// This keeps a working reference to that file, yet we don't
// have to deal with the cleanup any more.
let fh = try FileHandle(forReadingFrom: fileURL)
let mappedFile = try Data(contentsOf: fileURL, options: [.alwaysMapped])
try FileManager.default.removeItem(at: fileURL)
Task {
while let data = try fh.read(upToCount: 64 * 1024 * 1024) {
await dataCh.send(data)
for chunk in (0 ..< mappedFile.count).chunks(ofCount: 64 * 1024 * 1024) {
await dataCh.send(mappedFile.subdata(in: chunk))
}
dataCh.finish()

View File

@ -253,7 +253,7 @@ class Registry {
for try await part in channel {
try Task.checkCancellation()
try await handler(Data(part))
try await handler(part)
}
}