From 369f338a4d06f551797391885da582a0467d250b Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Fri, 2 Aug 2024 14:20:59 -0700 Subject: [PATCH] Add FoundationNetworking hook for reading contents of remote URL --- Sources/FoundationEssentials/Data/Data.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/FoundationEssentials/Data/Data.swift b/Sources/FoundationEssentials/Data/Data.swift index 40fee4a2c..ad3ac42e9 100644 --- a/Sources/FoundationEssentials/Data/Data.swift +++ b/Sources/FoundationEssentials/Data/Data.swift @@ -2079,6 +2079,14 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect public static let fileProtectionMask = WritingOptions(rawValue: 0xf0000000) } #endif + + #if !FOUNDATION_FRAMEWORK + @_spi(SwiftCorelibsFoundation) + public dynamic init(_contentsOfRemote url: URL, options: ReadingOptions = []) throws { + assert(!url.isFileURL) + throw CocoaError(.fileReadUnsupportedScheme) + } + #endif /// Initialize a `Data` with the contents of a `URL`. /// @@ -2098,7 +2106,7 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect let d = try NSData(contentsOf: url, options: NSData.ReadingOptions(rawValue: options.rawValue)) self.init(referencing: d) #else - throw CocoaError(.fileReadUnsupportedScheme) + try self.init(_contentsOfRemote: url, options: options) #endif } #endif