-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6 Promise version .vm #42
Comments
Hey this looks good, but I'm wondering if we can just update the existing mv method instead. If a callback is passed in, it executes a callback. Otherwise, it returns a promise. Make sense? |
Yeah, of course, why not? mv: function(path, callback) {
if (callback) {
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', error => callback(error));
fstream.on('close', () => callback(null));
} else {
return new Promise((resolve, reject) => {
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', error => reject(error));
fstream.on('close', () => resolve(null));
});
}
} And if you dislike lambda expression... mv: function(path, callback) {
if (callback) {
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', function (error) {
callback(error);
});
fstream.on('close', function () {
callback(null);
});
} else {
return new Promise((resolve, reject) => {
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', function (error) {
reject(error);
});
fstream.on('close', function () {
resolve(null);
});
});
}
} Plus a way to reduce one level of indention: mv: function(path, callback) {
if (!callback) {
return new Promise((resolve, reject) => {
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', error => reject(error));
fstream.on('close', () => resolve(null));
});
}
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', error => callback(error));
fstream.on('close', () => callback(null));
} And the old fashion: mv: function(path, callback) {
if (!callback) {
return new Promise((resolve, reject) => {
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', function (error) {
reject(error);
});
fstream.on('close', function () {
resolve(null);
});
});
}
let fstream = fs.createWriteStream(path);
streamifier.createReadStream(buf).pipe(fstream);
fstream.on('error', function (error) {
callback(error);
});
fstream.on('close', function () {
callback(null);
});
} |
This was referenced Nov 18, 2019
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#24
Open
Open
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#35
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#47
Open
Open
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#58
Open
Open
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#69
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#80
Open
Open
Open
[Snyk(Unlimited)] Upgrade express-fileupload from 0.0.5 to 0.4.0
snyk-fixtures/js-nested-manifest#91
Open
Open
Open
This was referenced Nov 25, 2019
Open
This was referenced Apr 15, 2020
This was referenced Apr 22, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to add a ES6 Promise version of the .mv function.
Here's the draft:
This should be appended after the
.vm
definition inlet newFile
.Any suggestions? If this looks good, I'll create a pull request with a test.
The text was updated successfully, but these errors were encountered: