- Version: Node.js v7.1.0
- Platform: Darwin Kernel Version 16.1.0
As stated in the issue title, Buffer.isEncoding('') returns true.
Actually, passing an empty string to encoding options of fs.readFile, Buffer.from or other functions supporting encoding doesn't result in an error, because they use the default encoding utf8 as a fallback in that case.
From this point of view, '' is also a valid encoding and Buffer.isEncoding('') === true looks fine. However, if we approve this behavior of Buffer.isEncoding, I think it's inconsistent that Buffer.isEncoding returns false when it takes other falsy values − false, null, undefined etc.
So, which design of Buffer.isEncoding is most reasonable?
- There is no problem with the current behavior of
Buffer.isEncoding.
Buffer.isEncoding should return false when it takes ''.
Buffer.isEncoding should return true when it takes any falsy values.
I support the second one and can create a pull request.
I'd like to hear your opinion. Thanks.