Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / testswarm / node_modules / request / node_modules / form-data / node_modules / combined-stream / test / integration / test-unpaused-streams.js
1 var common = require('../common');
2 var assert = common.assert;
3 var CombinedStream = common.CombinedStream;
4 var fs = require('fs');
5
6 var FILE1 = common.dir.fixture + '/file1.txt';
7 var FILE2 = common.dir.fixture + '/file2.txt';
8 var EXPECTED = fs.readFileSync(FILE1) + fs.readFileSync(FILE2);
9
10 (function testDelayedStreams() {
11   var combinedStream = CombinedStream.create({pauseStreams: false});
12   combinedStream.append(fs.createReadStream(FILE1));
13   combinedStream.append(fs.createReadStream(FILE2));
14
15   var stream1 = combinedStream._streams[0];
16   var stream2 = combinedStream._streams[1];
17
18   stream1.on('end', function() {
19     assert.ok(stream2.dataSize > 0);
20   });
21
22   var tmpFile = common.dir.tmp + '/combined.txt';
23   var dest = fs.createWriteStream(tmpFile);
24   combinedStream.pipe(dest);
25
26   dest.on('end', function() {
27     var written = fs.readFileSync(tmpFile, 'utf8');
28     assert.strictEqual(written, EXPECTED);
29   });
30 })();