FileOpener automates opening files and retrieving their contents. It employs Stuk's library JSZip to open and retrieve files in zipped archives.
Download fileOpener.js and include it wherever needed.
FileOpener can be used in multiple ways. The following examples will behave the same:
//Create a new instance of FileOpener: Call FileOpener constructor by using keyword new
var opener = new FileOpener();
opener.getFilesFromList(fileList)
.then(workWithFileContents, handleErrors);
//Call function directly
FileOpener.getFilesFromList(fileList)
.then(workWithFileContents, handleErrors);
function workWithFileContents(result)
{
console.log(result);
}
function handleErrors(err)
{
console.log(err);
}
FileOpener offers three methods to use:
- getFile - returns a promise of an object with the properties name and content of a single file or blob.
- getFilesFromZip - returns a promise of an array of above described objects.
- getFilesFromList - returns a promise of a (nested) array of above described objects.
The arrays in 2 and 3 can be flattened using the simplify-method.