javascript - Error: EMFILE: too many open files -
using nw.js, trying save images in array of img elements different random names.
but having few errors, wrong code?
for (i = 0; < imgs.length; i++) { request(imgs[i].getattribute('src')).on('error', function(err) { throw err }).pipe(fs.createwritestream('data/imgs/' + randomstring)) }
imgs[] array of 100-500 html img element, receiving
error: emfile: many open files, open *<directory>*
and error:
"uncaught error: socket hang up"
although saves images, of them corrupted, , creates many images there is.
use graceful-fs
module, drop-in replacement fs
module. wrapper around native fs
module. quoting docs of graceful-fs
module,
queues
open
,readdir
calls, , retries them once closes if thereemfile
error many file descriptors.
since exposes same apis native fs
module, can use normal fs
module.
// use fs var fs = require('graceful-fs');
note: library created by, isaac z. schlueter, 1 of core developers of node.js.
Comments
Post a Comment