-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: set encoding if option argument is string
- Loading branch information
1 parent
4969579
commit 2f418b6
Showing
5 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const stream = require('stream'); | ||
const encoding = 'base64'; | ||
|
||
const example = path.join(common.fixturesDir, 'x.txt'); | ||
const assertStream = new stream.Writable({ | ||
write: function(chunk, enc, next) { | ||
const expected = new Buffer('xyz'); | ||
assert(chunk.equals(expected)); | ||
} | ||
}); | ||
assertStream.setDefaultEncoding(encoding); | ||
fs.createReadStream(example, encoding).pipe(assertStream); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const stream = require('stream'); | ||
const firstEncoding = 'base64'; | ||
const secondEncoding = 'binary'; | ||
|
||
const example = path.join(common.fixturesDir, 'x.txt'); | ||
const dummy = path.join(common.tmpDir, '/x.txt'); | ||
const exampleReadStream = fs.createReadStream(example, firstEncoding); | ||
const dummyWriteStream = fs.createWriteStream(dummy, firstEncoding); | ||
exampleReadStream.pipe(dummyWriteStream).on('finish', function(){ | ||
const assertWriteStream = new stream.Writable({ | ||
write: function(chunk, enc, next) { | ||
const expected = new Buffer('xyz\n'); | ||
assert(chunk.equals(expected)); | ||
} | ||
}); | ||
assertWriteStream.setDefaultEncoding(secondEncoding); | ||
fs.createReadStream(dummy, secondEncoding).pipe(assertWriteStream); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|