ios - how to read a huge array of bytes in chunks - pj_strset -
i working on ios project
i have read huge file in chunks of 4kb here have far:
nsdata *filedata= [self getbytesfrominput]; pj_str_t text; int chunksize = 4*1024; int filesize = [filedata length]; while (filesize>0){ if (filesize<=chunksize) { chunksize = filesize; filesize=0; } else filesize = filesize-chunksize; pj_strset(&text, (char*)[filedata bytes], min([filedata length], chunksize); //takes first chunk //but how take next chunk of data? //do &text .... }
i refactor code loading files in chunks, can access later chunks adding offset byte-pointer:
int currentoffset = 0; while (filesize>0) { ... char* bytepointer = (char*)[filedata bytes]; pj_strset(&text, bytepointer+currentoffset, min([filedata length], chunksize); currentoffset += chunksize; }
edit:
this should same thing reading file chunk chunk:
nsstring *yourfilepath; nsfilehandle *filehandle = [nsfilehandle filehandleforreadingatpath:yourfilepath]; int chunksize = 4*1024; pj_str_t text; nsdata *data; while ((data = [filehandle readdataoflength:chunksize]) && [data length] > 0) { pj_strset(&text, (char*)[data bytes], [data length]); }
Comments
Post a Comment