0

My App would download a file which the first 12 byte data was encrypted,so I have to read this file from Document and decrypt the first 12 byte data.

My first try was to read the whole file and decrypt it then write to file again. but if the file is too large , this will cost a lot of memory.

So ,Is there anyway to let me read the first 12 byte data and replace it?

johnMa
  • 3,291
  • 24
  • 37

3 Answers3

1

This is a std way of doing in any language.

Read a file in chunk Replace in Buffer write in Temporary file delete the original file and rename temporary file as original file.

As far as objective C concerned i found a useful link

http://www.techotopia.com/index.php/Working_with_Files_in_Objective-C

goto this topic "Writing Data to a File"

user1627167
  • 339
  • 1
  • 8
0

Well Objective-C is based on C and hence all the functions including file-operation functions should work out-of-the-box. You can convert the NSString file-path to char array and perform the desired file operations with the help of the this link.

Varun Singh
  • 1,135
  • 13
  • 18
0
#include <stdio.h>

FILE *f = fopen("yourFileName", "rb");
if(f == NULL)
    ; // handle exception
int nBytesToRead;
char theBuffer[nBytesToRead];  
size_t bytesRead = fread(theBuffer, 1, nBytesToRead, f);
// do with your bytesRead
fclose(f);