title: Writing Data to an OutputStream with Swift 5+
body: <p>This code used to be fine (in the sense that the compiler didn't complain):</p>
  
  <pre><code>extension OutputStream {
      func write(_ data: Data) -&gt; Int {
          return data.withUnsafeBytes { pointer in
              return self.write(pointer, maxLength: data.count)
          }
      }
  }
  </code></pre>
  
  <p>Since Swift 5.0, this produces a warning:</p>
  
  <blockquote>
    <p>Warning: 'withUnsafeBytes' is deprecated: use <code>withUnsafeBytes&lt;R&gt;(_: (UnsafeRawBufferPointer) throws -&gt; R) rethrows -&gt; R</code> instead</p>
  </blockquote>
  
  <p>I tried using the proposed method but I can't seem to wrangle the <code>UnsafeRawBufferPointer</code> into the <code>UnsafePointer&lt;UInt8&gt;</code> that <code>OutputStream.write</code> ultimately requires.</p>
  
  <p>How can I write this function in a non-deprecated way?</p>