jQuery plugin for chunked file reading.
Basic setup
$('input[type=file]').cfr();
Options
chunkSize- chunk size in bytes.readFunc- function to call on FileReader (readAsDataURLby default ).filter- function to call on chunk before pass it toonChunkcallback (function (c) { return c.substr(c.indexOf(',') + 1); }by default).
If you override a readFunc you also need override a default filter or pass it a null.
Callbacks
onStart(file)- will be called before reading first chunk.file- File object.
onChunk(chunk, size, chunkNum, chunks, file, cb)- will be called on each chunk.chunk- output offilterfunction if present. Instead a result of FileReadersonloadendevent.size- count of bytes read fromfile.chunkNum- number of chunk.chunks- count of chunks in file.file- File object.cb- function you must call to continue reading. You also can callcb(true)to cancel reading and triggeronCancelcallback.
onCancel(file)- will be called aftercb(true)or.cfr('cancel').file- File object.
onFinish(file)- will be called after last chunk read.file- File object.
onEnd(file)- will be called afteronCanceloronFinishfile- File object.
onNotSupported()- will be called on plugin initialization if FileReader API is not supported.
Methods
.cfr('cancel')- cancel reading process.cfr('remove')- removing cfr from element (does not abort read process)
Example
See test.html for complete example.