aboutsummaryrefslogtreecommitdiff
path: root/uploader/static/js/files.js
blob: c1dedad62406cf7e911f7f685bfb3f1ef0fbf83e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var read_first_n_lines = (fileelement, count, process_content_fns) => {
    var thefile = fileelement.files[0];
    var reader = new FileReader();
    if(typeof thefile !== "undefined" && thefile !== null) {
        reader.addEventListener("load", (event) => {
            var content = event
                .target
                .result
                .split("\n")
                .slice(0, count)
                .map((line) => {return line.trim("\r");});
            process_content_fns.forEach((fn) => {fn(content);});
        });
        reader.readAsText(thefile);
    }
};