title: Swift Calculate MD5 Checksum for Large Files
body: <p>I'm working on creating the MD5 Checksum for large video files. I'm currently using the code:</p>
  
  <pre><code>extension NSData {
  func MD5() -&gt; NSString {
      let digestLength = Int(CC_MD5_DIGEST_LENGTH)
      let md5Buffer = UnsafeMutablePointer&lt;CUnsignedChar&gt;.allocate(capacity: digestLength)
  
      CC_MD5(bytes, CC_LONG(length), md5Buffer)
      let output = NSMutableString(capacity: Int(CC_MD5_DIGEST_LENGTH * 2))
      for i in 0..&lt;digestLength {
          output.appendFormat("%02x", md5Buffer[i])
      }
  
      return NSString(format: output)
      }
  }
  </code></pre>
  
  <p>But that creates a memory buffer, and for large video files would not be ideal. Is there a way in Swift to calculate the MD5 Checksum reading a file stream, so the memory footprint will be minimal?</p>