Skip to content

blackbeam/cfr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cfr

jQuery plugin for chunked file reading.

Basic setup

$('input[type=file]').cfr();

Options

  • chunkSize - chunk size in bytes.
  • readFunc - function to call on FileReader (readAsDataURL by default ).
  • filter - function to call on chunk before pass it to onChunk callback (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 of filter function if present. Instead a result of FileReaders onloadend event.
    • size - count of bytes read from file.
    • chunkNum - number of chunk.
    • chunks - count of chunks in file.
    • file - File object.
    • cb - function you must call to continue reading. You also can call cb(true) to cancel reading and trigger onCancel callback.
  • onCancel(file) - will be called after cb(true) or .cfr('cancel').
    • file - File object.
  • onFinish(file) - will be called after last chunk read.
    • file - File object.
  • onEnd(file) - will be called after onCancel or onFinish
    • file - 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.

About

jQuery chunked file read plugin

Resources

Stars

Watchers

Forks

Packages

No packages published