diff --git a/Sources/Foundation/FileManager+Win32.swift b/Sources/Foundation/FileManager+Win32.swift index 46ece380b1..949bd14e76 100644 --- a/Sources/Foundation/FileManager+Win32.swift +++ b/Sources/Foundation/FileManager+Win32.swift @@ -24,7 +24,7 @@ extension URL { #"\\?\\#(CFURLCopyFileSystemPath(CFURLCopyAbsoluteURL(_cfObject), kCFURLWindowsPathStyle)!._swiftObject)"# } - fileprivate func withUnsafeNTPath(_ body: (UnsafePointer) throws -> Result) rethrows -> Result { + internal func withUnsafeNTPath(_ body: (UnsafePointer) throws -> Result) rethrows -> Result { try self.NTPath.withCString(encodedAs: UTF16.self, body) } } diff --git a/Sources/Foundation/NSData.swift b/Sources/Foundation/NSData.swift index 9892d0968b..ed9e7f0529 100644 --- a/Sources/Foundation/NSData.swift +++ b/Sources/Foundation/NSData.swift @@ -209,10 +209,16 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { internal static func contentsOf(url: URL, options readOptionsMask: ReadingOptions = []) throws -> (result: NSData, textEncodingNameIfAvailable: String?) { if url.isFileURL { +#if os(Windows) + return try url.withUnsafeNTPath { + return (try NSData.readBytesFromFileWithExtendedAttributes(String(decodingCString: $0, as: UTF16.self), options: readOptionsMask).toNSData(), nil) + } +#else return try url.withUnsafeFileSystemRepresentation { (fsRep) -> (result: NSData, textEncodingNameIfAvailable: String?) in let data = try NSData.readBytesFromFileWithExtendedAttributes(String(cString: fsRep!), options: readOptionsMask) return (data.toNSData(), nil) } +#endif } else { return try _NSNonfileURLContentLoader.current.contentsOf(url: url) }