Merge pull request #70 from walkonsocial/master
Fix for issues - #58, #23 & #67
This commit is contained in:
commit
382f9e1a1f
|
@ -166,7 +166,14 @@ FileSystemProvider.prototype.upload = function (options, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return fs.createWriteStream(filePath, fileOpts);
|
//simulate the success event in filesystem provider
|
||||||
|
//fixes: https://github.com/strongloop/loopback-component-storage/issues/58
|
||||||
|
// & #23 & #67
|
||||||
|
var stream = fs.createWriteStream(filePath, fileOpts);
|
||||||
|
stream.on('finish', function(){
|
||||||
|
stream.emit('success');
|
||||||
|
});
|
||||||
|
return stream;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
cb && cb(e);
|
cb && cb(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,10 @@ exports.upload = function (provider, req, res, options, cb) {
|
||||||
self._maybeEnd();
|
self._maybeEnd();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
writer.on('success', function (file) {
|
||||||
|
endFunc();
|
||||||
|
});
|
||||||
|
|
||||||
var fileSize = 0;
|
var fileSize = 0;
|
||||||
if (maxFileSize) {
|
if (maxFileSize) {
|
||||||
part.on('data', function (buffer) {
|
part.on('data', function (buffer) {
|
||||||
|
@ -149,7 +153,6 @@ exports.upload = function (provider, req, res, options, cb) {
|
||||||
part.pipe(writer, { end: false });
|
part.pipe(writer, { end: false });
|
||||||
part.on("end", function () {
|
part.on("end", function () {
|
||||||
writer.end();
|
writer.end();
|
||||||
endFunc();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,13 @@ describe('Storage service', function () {
|
||||||
writer.on('finish', done);
|
writer.on('finish', done);
|
||||||
writer.on('error', done);
|
writer.on('error', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit success event', function (done) {
|
||||||
|
var writer = storageService.uploadStream('c1', 'f1.txt');
|
||||||
|
fs.createReadStream(path.join(__dirname, 'files/f1.txt')).pipe(writer);
|
||||||
|
writer.on('success', done);
|
||||||
|
writer.on('error', done);
|
||||||
|
});
|
||||||
|
|
||||||
it('should download a file', function (done) {
|
it('should download a file', function (done) {
|
||||||
var reader = storageService.downloadStream('c1', 'f1.txt');
|
var reader = storageService.downloadStream('c1', 'f1.txt');
|
||||||
|
|
Loading…
Reference in New Issue