summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/integration/test-delayed-streams-and-buffers-and-strings.js
blob: c678575c07b6367a5271ea4b3bb2e5d32b19b1cb (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
38
var common = require('../common');
var assert = common.assert;
var CombinedStream = common.CombinedStream;
var fs = require('fs');

var FILE1 = common.dir.fixture + '/file1.txt';
var BUFFER = new Buffer('Bacon is delicious');
var FILE2 = common.dir.fixture + '/file2.txt';
var STRING = 'The € kicks the $\'s ass!';

var EXPECTED =
  fs.readFileSync(FILE1)
  + BUFFER
  + fs.readFileSync(FILE2)
  + STRING;
var GOT;

(function testDelayedStreams() {
  var combinedStream = CombinedStream.create();
  combinedStream.append(fs.createReadStream(FILE1));
  combinedStream.append(BUFFER);
  combinedStream.append(fs.createReadStream(FILE2));
  combinedStream.append(function(next) {
    next(STRING);
  });

  var tmpFile = common.dir.tmp + '/combined-file1-buffer-file2-string.txt';
  var dest = fs.createWriteStream(tmpFile);
  combinedStream.pipe(dest);

  dest.on('close', function() {
    GOT = fs.readFileSync(tmpFile, 'utf8');
  });
})();

process.on('exit', function() {
  assert.strictEqual(GOT, EXPECTED);
});