1

I am working with large instances of ALAsset and I am trying to split the asset up into smaller chunks for uploading.

What is a good approach to split a large file up into smaller chunks without loading the entire file into memory?

1 Answers1

2

I did this in a text editor but it should compile. NSFileHandle is a thin wrapper around the UNIX file utilities.

    #define CHUNK_SIZE 2048

        NSFileHandle *fh = [NSFIleHandle fileHandleForReadingAtPath:<the file path as a 

string>];

    while(YES) {
        NDSata *chunk = [fh readDataOfLength:CHUNK_SIZE];

        NSUInteger length = [chunk length];
        if(length == 0) break; // done

        // send the data
    }
    fh = nil; // under arc this releases the object
David H
  • 40,852
  • 12
  • 92
  • 138