Use most up-to-date FileHandle APIs#74
Conversation
Codecov Report
@@ Coverage Diff @@
## main #74 +/- ##
==========================================
+ Coverage 96.44% 98.92% +2.47%
==========================================
Files 14 13 -1
Lines 591 556 -35
==========================================
- Hits 570 550 -20
+ Misses 21 6 -15
|
| patch: off | ||
|
|
||
| ignore: | ||
| - "Sources/CacheAdvance/FileHandleExtensions.swift" |
There was a problem hiding this comment.
Ignoring this file because due to limitations of Github Actions we can't test most of the branches in this file.
There was a problem hiding this comment.
Can we add a comment to this effect?
| patch: off | ||
|
|
||
| ignore: | ||
| - "Sources/CacheAdvance/FileHandleExtensions.swift" |
There was a problem hiding this comment.
Can we add a comment to this effect?
| if let data = try read(upToCount: length) { | ||
| return data | ||
| } else { | ||
| return Data() |
There was a problem hiding this comment.
It's interesting that the method both throws and returns a nullable result. I wonder how you could end up with nil? In any case, do you think we should throw our own error if the data is nil?
There was a problem hiding this comment.
Oh we end up with nil when the data is empty. I tried throwing here instead of returning Data() and I broke a ton of tests. Returning Data() here preserves existing behavior.
When iOS 13 / tvOS 13 / watchOS 6 / macOS 10.15 were released, Apple deprecated the readData(ofLength:) and the write(_:) methods, but did not replace them with any new documented methods. The only available, non-deprecated replacements for these methods were
__readDataUp(toLength:)and__write(_:, error:), but neither were documented.Then in iOS 13.4 / tvOS 13.4 / watchOS 6.2 / macOS 10.15.4 Apple fixed their mistake, introducing the APIs read(upToCount:) and write(contentsOf:). This PR adopts these newer methods.
It is expected that this PR will lower our code coverage, since we do not have CI running on iOS 13.0<=13.4 / tvOS 13.0<=13.4 / watchOS 6<=6.2 / macOS 10.15.0<=10.15.4