javascript - How to call to function with parameter from event -


i use following code working:

yauzl.open(filepath, function (err, zipfile) {     zipfile.on('entry', (entry) =>{         //console.log(entry.filename);         if (/\/$/.test(entry.filename)) {             return;         }         zipfile.openreadstream(entry, (err, readstream) => {             if (err) {                 logger.info(err);                 reject(err);             } else {     ... 

now want change code bit make more readable doing following:

yauzl.open(filepath, (err, zipfile) => {     //zipfile = zipfile;     if (err) {         __rejectandlog(err);         return;     }      zipfile.on('entry', __processentry(zipfile))         .once('error', __rejectandlog)         .once('close', () => {             console.log(`unpacked ${numoffiles} files`);             resolve();         });     }); 

this processentry:

function __processentry(zipfile) {      zipfile.openreadstream(entry, (err, readstream) => {         if (err) {             __rejectandlog(err);             return;         }          if (/\/$/.test(entry.filename)) {             // directory file names end '/'                return;         } 

here got error cannot use **openreadstream** of undefined. how can handle it?

zipfile.openreadstream(entry, (err, readstream) => { 

in addition need pass entry value idea?

use bind zipfile.on('entry', __processentry.bind(null, zipfile)) , re-declare __processentry function __processentry(zipfile, entry)


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -