开发者

Extract contents of binary file cocoa

开发者 https://www.devze.com 2023-03-25 09:57 出处:网络
I am working on an encryption too开发者_StackOverflow中文版l, and I need to be able to encrypt the contents of any binary file whether it be text or sound. How can I extract the contents of the file a

I am working on an encryption too开发者_StackOverflow中文版l, and I need to be able to encrypt the contents of any binary file whether it be text or sound. How can I extract the contents of the file and use that to encrypt. I already have my encryption set, but it is of no use if I have nothing to encrypt.

Your help is greatly appreciated

Thanks!


The simplest way, if you can afford loading the whole file into memory is:

NSData* data = [NSData dataWithContentsOfFile:yourPath];

Otherwise you can use NSFileHandle:

NSFileHandle* fileH = [NSFileHandle fileHandleForReadingAtPath:yourPath];
NSData* dataChunk = [fileH readDataOfLength:maxSize];

See also NSData Reference or NSFileHandle Reference

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号