0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-read-stream-resume.js

32 lines
599 B
JavaScript
Raw Normal View History

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const file = path.join(common.fixturesDir, 'x.txt');
let data = '';
let first = true;
var stream = fs.createReadStream(file);
stream.setEncoding('utf8');
stream.on('data', function(chunk) {
data += chunk;
if (first) {
first = false;
stream.resume();
}
});
process.nextTick(function() {
stream.pause();
setTimeout(function() {
stream.resume();
}, 100);
});
process.on('exit', function() {
assert.strictEqual(data, 'xyz\n');
});