-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Expose readFile encoding option through vfs.src #66
Conversation
@@ -14,7 +15,9 @@ function getContents(opt) { | |||
|
|||
// read and pass full contents | |||
if (opt.buffer !== false) { | |||
return bufferFile(file, cb); | |||
// set encoding type if user specifies it | |||
var options = 'encoding' in opt ? {'encoding': opt.encoding} : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just var options = { encoding: opt.encoding }
? If opt.encoding
is undefined, it'll be passed through as undefined, which is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed.
lgtm except for the one thing |
Test fail? |
@contra it's failing upstream |
file.contents = stripBom(data); | ||
// if user specifies encoding type, a string is returned | ||
// so we need to convert it back to buffer | ||
if (!Buffer.isBuffer(data) && typeof data === 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just typeof is sufficient here, no need for both checks. then you can make this a ternary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (typeof data === 'string') {
data = new Buffer(data, opt.encoding);
}
file.contents = stripBom(data);
would be cleanest imo
How does this work with writing files out? Aren't we going to need to specify the encoding there as well |
@contra I understand without passing encoding to writing out, all this is kind of pointless. I just made the PR to see if I'm on the right track. Will add |
What use-case is this solving exactly? When would you ever need to be able to specify |
Encoding doesn't really make sense because we always read in as buffer, which doesn't have an encoding. Plugins use |
I would think https://github.com/heldinz/gulp-convert-encoding would be a better solution if you're using obscure encodings. |
Hi guys, so sorry I completely forgot about this PR. It was more than a month ago and I have indeed found out that it's better to convert my stuff to sane encoding first rather than requiring it from gulp/vinyl-fs. Thanks for your comments. I'm closing this. |
Here is a PR for
src
regarding #23.I will add support for
dest
if this is up to par :)