         }
       }
 #else
-        guard _fd >= 0 else { return }
         data.enumerateBytes() { (bytes, range, stop) in
             do {
                 try NSData.write(toFileDescriptor: self._fd, path: nil, buf: UnsafeRawPointer(bytes.baseAddress!), length: bytes.count)

    }

    open func write(_ data: Data) {
#if os(Windows)
      precondition(_handle != INVALID_HANDLE_VALUE, "invalid file handle")
      data.enumerateBytes() { (bytes, range, stop) in
        do {
          try NSData.write(toHandle: self._handle, path: nil,

open class FileHandle : NSObject, NSSecureCoding {
#if os(Windows)
    private var _handle: HANDLE

    @available(windows, unavailable, message: "Cannot perform non-owning handle to fd conversion")
    open var fileDescriptor: Int32 {
        NSUnsupported()
    }

    private func _checkFileHandle() {
        precondition(_handle != INVALID_HANDLE_VALUE, "Invalid file handle")
    }

#else
    private var _fd: Int32

    open var fileDescriptor: Int32 {
        return _fd
    }

    private func _checkFileHandle() {
        precondition(_fd >= 0, "Bad file descriptor")
    }
#endif

    private var _closeOnDealloc: Bool


    open var readabilityHandler: ((FileHandle) -> Void)? = {
      (FileHandle) -> Void in NSUnimplemented()
    }

    open var writeabilityHandler: ((FileHandle) -> Void)? = {
      (FileHandle) -> Void in NSUnimplemented()
    }

    open var availableData: Data {
        _checkFileHandle()
        do {
            let readResult = try _readDataOfLength(Int.max, untilEOF: false)
            return readResult.toData()
