File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public extension FeedType {
84
84
}
85
85
86
86
/// The number of bytes to inspect when determining the feed type.
87
- private let inspectionPrefixLength = 200
87
+ private let inspectionPrefixLength = 128
88
88
89
89
// MARK: - FeedInitializable
90
90
@@ -94,8 +94,12 @@ extension FeedType: FeedInitializable {
94
94
/// - Parameter data: A `Data` object representing a feed to be inspected.
95
95
/// - Returns: A `FeedType` if the data matches a known feed format, otherwise `nil`.
96
96
public init ( data: Data ) throws {
97
- // Inspect only the first 200 bytes. This helps improve performance while
98
- // still providing enough data to reliably detect the feed format.
97
+ guard data. count >= inspectionPrefixLength else {
98
+ throw FeedError . unknownFeedFormat
99
+ }
100
+
101
+ // Inspect only the first `inspectionPrefixLength` bytes. This helps improve performance
102
+ // while still providing enough data to reliably detect the feed format.
99
103
let string : String = . init( decoding: data. prefix ( inspectionPrefixLength) , as: UTF8 . self)
100
104
101
105
// Determine the feed type
You can’t perform that action at this time.
0 commit comments