summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream2-base64-single-char-read-end.js
blob: 1b14b7f6b4517cc6924ad57096205335a36f1f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const common = require('../common');
const R = require('_stream_readable');
const W = require('_stream_writable');
const assert = require('assert');

const src = new R({encoding: 'base64'});
const dst = new W();
let hasRead = false;
const accum = [];
let timeout;

src._read = function(n) {
  if (!hasRead) {
    hasRead = true;
    process.nextTick(function() {
      src.push(Buffer.from('1'));
      src.push(null);
    });
  }
};

dst._write = function(chunk, enc, cb) {
  accum.push(chunk);
  cb();
};

src.on('end', function() {
  assert.equal(Buffer.concat(accum) + '', 'MQ==');
  clearTimeout(timeout);
});

src.pipe(dst);

timeout = setTimeout(function() {
  common.fail('timed out waiting for _write');
}, 100);