• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4const fixtures = require('../common/fixtures');
5const fs = require('fs');
6const path = require('path');
7const stream = require('stream');
8const tmpdir = require('../common/tmpdir');
9const firstEncoding = 'base64';
10const secondEncoding = 'latin1';
11
12const examplePath = fixtures.path('x.txt');
13const dummyPath = path.join(tmpdir.path, 'x.txt');
14
15tmpdir.refresh();
16
17const exampleReadStream = fs.createReadStream(examplePath, {
18  encoding: firstEncoding
19});
20
21const dummyWriteStream = fs.createWriteStream(dummyPath, {
22  encoding: firstEncoding
23});
24
25exampleReadStream.pipe(dummyWriteStream).on('finish', function() {
26  const assertWriteStream = new stream.Writable({
27    write: function(chunk, enc, next) {
28      const expected = Buffer.from('xyz\n');
29      assert(chunk.equals(expected));
30    }
31  });
32  assertWriteStream.setDefaultEncoding(secondEncoding);
33  fs.createReadStream(dummyPath, {
34    encoding: secondEncoding
35  }).pipe(assertWriteStream);
36});
37