Last active
October 8, 2019 14:50
-
-
Save tsif/6ae071c17119735ed3659d46d51ff8b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hasher = SHA256() | |
let path = Bundle.main.path(forResource: "video", ofType: "mp4")! | |
let stream = InputStream(fileAtPath: path)! | |
stream.open() | |
let bufferSize = 512 | |
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize) | |
while stream.hasBytesAvailable { | |
let read = stream.read(buffer, maxLength: bufferSize) | |
let bufferPointer = UnsafeRawBufferPointer(start: buffer, count: read) | |
hasher.update(bufferPointer: bufferPointer) | |
} | |
let digest = hasher.finalize() | |
print(digest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment