1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-16 08:13:30 +00:00

1. Fixed crash that could happen when you close a FD in fs.closeSync()

2. Added 'cancel' method/event to zip-writer.js
3. Fixed bug in Windows Zip-Writer when parsing basePath
4. Added ability to manually specify basePath in Zip-Writer
This commit is contained in:
Bryan Roe
2020-08-18 11:09:56 -07:00
parent 376d51cb9e
commit 321cae9eb0
3 changed files with 38 additions and 5 deletions

View File

@@ -49,7 +49,14 @@ function getBaseFolder(val)
for (i = 0; i < val.length; ++i)
{
test.push(val[i].split(D));
if (process.platform == 'win32')
{
test.push(val[i].split('/').join('\\').split(D));
}
else
{
test.push(val[i].split(D));
}
}
if (val.length == 1)
@@ -271,6 +278,13 @@ function write(options)
}
}
});
require('events').EventEmitter.call(ret, true)
.createEvent('cancel')
.addMethod('cancel', function(callback)
{
this._cancel = true;
if(callback!=null) { this.once('cancel', callback); }
});
ret._currentPosition = 0;
ret._ObjectID = 'zip-writer.duplexStream';
ret.bufferMode = 1;
@@ -282,11 +296,30 @@ function write(options)
ret.pause();
options._localFileTable = {};
options._baseFolder = getBaseFolder(options.files);
options._baseFolder = (options.basePath == null ? getBaseFolder(options.files) : options.basePath);
if (options._baseFolder != '')
{
if (!options._baseFolder.endsWith(process.platform == 'win32' ? '\\' : '/')) { options._baseFolder += (process.platform == 'win32' ? '\\' : '/'); }
}
ret._uncompressedReadSink = function _uncompressedReadSink(err, bytesRead, buffer)
{
var self = _uncompressedReadSink.self;
if(self._cancel)
{
self._compressor.end();
self._compressor.unpipe();
try
{
require('fs').closeSync(self._currentFD);
}
catch(e)
{}
self.options.files.length = 0;
self.emit('cancel');
self.end();
return;
}
if(bytesRead == 0)
{
// DONE