-
Notifications
You must be signed in to change notification settings - Fork 230
Description
Archiver has an upper bound memory limit when zipping a file.
For example, let's say you have a million files in a directory and you attempt to zip that directory.
`util.walkdir(dirpath, function(err, results) {
if (err) {
self.emit('error', err);
} else {
results.forEach(function(file) {
var entryData = _.extend({}, data);
entryData.name = file.relative;
entryData.prefix = destpath;
entryData.stats = file.stats;
try {
if (dataFunction) {
entryData = dataFunction(entryData);
if (typeof entryData !== 'object') {
throw new Error('directory: invalid data returned from custom function');
}
}
} catch(e) {
self.emit('error', e);
return;
}
self._append(file.path, entryData);
});
}
self._pending--;
self._maybeFinalize();
});
return this;
};`
If there happened to a plethora of files in the directory, (e.g. hundreds of thousands or a million) the results array becomes huge.
Then for each result, an entry data object is created and a task is ultimately created for each entry data. All that has to live in memory at the same time and will have a finite bound.
The task queue is a great idea but it seems like to alleviate memory pressure we should be filling it with a subset of files, burning down the queue, filling with next chunk of files....and then repeat.