11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst path = require('path');
71cb0ef41Sopenharmony_ciconst stream = require('stream');
81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
91cb0ef41Sopenharmony_ciconst firstEncoding = 'base64';
101cb0ef41Sopenharmony_ciconst secondEncoding = 'latin1';
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst examplePath = fixtures.path('x.txt');
131cb0ef41Sopenharmony_ciconst dummyPath = path.join(tmpdir.path, 'x.txt');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_citmpdir.refresh();
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst exampleReadStream = fs.createReadStream(examplePath, {
181cb0ef41Sopenharmony_ci  encoding: firstEncoding
191cb0ef41Sopenharmony_ci});
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciconst dummyWriteStream = fs.createWriteStream(dummyPath, {
221cb0ef41Sopenharmony_ci  encoding: firstEncoding
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciexampleReadStream.pipe(dummyWriteStream).on('finish', function() {
261cb0ef41Sopenharmony_ci  const assertWriteStream = new stream.Writable({
271cb0ef41Sopenharmony_ci    write: function(chunk, enc, next) {
281cb0ef41Sopenharmony_ci      const expected = Buffer.from('xyz\n');
291cb0ef41Sopenharmony_ci      assert(chunk.equals(expected));
301cb0ef41Sopenharmony_ci    }
311cb0ef41Sopenharmony_ci  });
321cb0ef41Sopenharmony_ci  assertWriteStream.setDefaultEncoding(secondEncoding);
331cb0ef41Sopenharmony_ci  fs.createReadStream(dummyPath, {
341cb0ef41Sopenharmony_ci    encoding: secondEncoding
351cb0ef41Sopenharmony_ci  }).pipe(assertWriteStream);
361cb0ef41Sopenharmony_ci});
37