@@ -433,10 +433,13 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
433433#if os(WASI)
434434 // WASI does not have permission concept
435435 let permissions : Int ? = nil
436+ // ReadingOptions.atomic won't be specified on WASI as it's marked unavailable
437+ var atomicWrite : Bool { false }
436438#else
437439 let permissions = try ? fm. attributesOfItem ( atPath: path) [ . posixPermissions] as? Int
440+ let atomicWrite = writeOptionsMask. contains ( . atomic)
438441#endif
439- if writeOptionsMask . contains ( . atomic ) {
442+ if atomicWrite {
440443 let ( newFD, auxFilePath) = try _NSCreateTemporaryFile ( path)
441444 let fh = FileHandle ( fileDescriptor: newFD, closeOnDealloc: true )
442445 do {
@@ -487,22 +490,38 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
487490
488491 /// Writes the data object's bytes to the file specified by a given path.
489492 /// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
493+ #if os(WASI)
494+ @available ( * , unavailable, message: " WASI does not support atomic file-writing as it does not have temporary directories " )
495+ #endif
490496 open func write( toFile path: String , atomically useAuxiliaryFile: Bool ) -> Bool {
497+ #if os(WASI)
498+ // WASI does not support atomic file-writing as it does not have temporary directories
499+ return false
500+ #else
491501 do {
492502 try write ( toFile: path, options: useAuxiliaryFile ? . atomic : [ ] )
493503 } catch {
494504 return false
495505 }
496506 return true
507+ #endif
497508 }
498509
499510 /// Writes the data object's bytes to the location specified by a given URL.
500511 /// NOTE: the 'atomically' flag is ignored if the url is not of a type the supports atomic writes
512+ #if os(WASI)
513+ @available ( * , unavailable, message: " WASI does not support atomic file-writing as it does not have temporary directories " )
514+ #endif
501515 open func write( to url: URL , atomically: Bool ) -> Bool {
516+ #if os(WASI)
517+ // WASI does not support atomic file-writing as it does not have temporary directories
518+ return false
519+ #else
502520 if url. isFileURL {
503521 return write ( toFile: url. path, atomically: atomically)
504522 }
505523 return false
524+ #endif
506525 }
507526
508527 /// Writes the data object's bytes to the location specified by a given URL.
0 commit comments