Skip to content

Commit

Permalink
Fix issues with finish event firing multiple times #10
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisiirak committed Aug 14, 2016
1 parent c53687a commit cc75b67
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
9 changes: 3 additions & 6 deletions lib/webhdfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,15 @@ WebHDFS.prototype.readFile = function readFile (path, callback) {
var data = [];
var error = null;

remoteFileStream.on('error', function onError (err) {
remoteFileStream.once('error', function onError (err) {
error = err;
});

remoteFileStream.on('data', function onData (chunk) {
data.push(chunk);
});

remoteFileStream.on('finish', function () {
remoteFileStream.once('finish', function () {
if (!error) {
return callback && callback(null, Buffer.concat(data));
} else {
Expand Down Expand Up @@ -562,7 +562,7 @@ WebHDFS.prototype.createWriteStream = function createWriteStream (path, append,
}
});

req.on('error', function onError (err) {
req.once('error', function onError (err) {
req.emit('finish'); // Request is finished
});

Expand Down Expand Up @@ -635,9 +635,6 @@ WebHDFS.prototype.createReadStream = function createReadStream (path, opts) {
}, this._requestParams);

var req = request(params);
req.on('error', function (err) {
req.emit('finish');
});

req.on('complete', function (err) {
req.emit('finish');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webhdfs",
"version": "0.3.0",
"version": "1.0.0",
"description": "Node.js WebHDFS REST API client",
"main": "lib/webhdfs.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion test/webhdfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ describe('WebHDFS', function () {
done();
});
});

it('should open and read a file', function (done) {
hdfs.readFile(path + '/file-1', function (err, data) {
demand(err).be.null();
Expand Down

0 comments on commit cc75b67

Please sign in to comment.