fs: check stream option and set encoding on fs.WritableStream#1412
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reviewer: @bnoordhuis
Problem 1
On Node.js v0.12
On io.js v1.6.4
Bug found modules
Cause
I found this pull request #635 . this PR uses
Object.createin createReadStream.Object.createdoes not acceptstring.Of course, the above scripts and modules are weird. we have never written such options in our api document.
BUT I have 2 opinions.
TypeError: Object prototype may only be an Object or null: utf8) is not so easy to understand. We should returnBad Argumentslike other functions.fs.createReadStreamandfs.createWriteStreamshould accept 2nd string argument as an encoding type. our existing functions likefs.readFile,fs.writeFile, have same behavior like here. the behavior misleads some developers.Fix
Problem2
According to the createWriteStream api docs,
encodingoption could be found in the default.But I set the encoding option to
fs.createWriteStream('foo.txt',{encoding: 'utf8'}), the encoding option is ignored.Fix
This pull request includes the fix both problem1 and problem2. comments and discussions are welcome.