From ed7462885fbac929616c6ccba3623fceb2b3b4a5 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 11 Apr 2013 21:45:16 +1000 Subject: [PATCH] backporting new streams to node 0.8 for issue #129 --- lib/streams/BaseRollingFileStream.js | 13 ++++++++++--- package.json | 4 +++- test/streams/DateRollingFileStream-test.js | 12 ++++++++++-- test/streams/rollingFileStream-test.js | 12 ++++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/streams/BaseRollingFileStream.js b/lib/streams/BaseRollingFileStream.js index 9409909..3bd8b2b 100644 --- a/lib/streams/BaseRollingFileStream.js +++ b/lib/streams/BaseRollingFileStream.js @@ -1,6 +1,13 @@ var fs = require('fs'), -stream = require('stream'), -util = require('util'); +stream, +util = require('util'), +semver = require('semver'); + +if (semver.satisfies(process.version, '>=0.10.0')) { + stream = require('stream'); +} else { + stream = require('readable-stream'); +} var debug; if (process.env.NODE_DEBUG && /\blog4js\b/.test(process.env.NODE_DEBUG)) { @@ -69,7 +76,7 @@ BaseRollingFileStream.prototype.openTheStream = function(cb) { BaseRollingFileStream.prototype.closeTheStream = function(cb) { debug("closing the underlying stream"); - this.theStream.end(null, null, cb); + this.theStream.end(cb); }; BaseRollingFileStream.prototype.shouldRoll = function() { diff --git a/package.json b/package.json index 41263f6..51b7d54 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ }, "dependencies": { "async": "0.1.15", - "dequeue": "1.0.3" + "dequeue": "1.0.3", + "semver": "~1.1.4", + "readable-stream": "~1.0.2" }, "devDependencies": { "vows": "0.7.0", diff --git a/test/streams/DateRollingFileStream-test.js b/test/streams/DateRollingFileStream-test.js index 0c18955..0d97cf1 100644 --- a/test/streams/DateRollingFileStream-test.js +++ b/test/streams/DateRollingFileStream-test.js @@ -1,10 +1,18 @@ var vows = require('vows') , assert = require('assert') -, streams = require('stream') , fs = require('fs') -, DateRollingFileStream = require('../../lib/streams').DateRollingFileStream +, semver = require('semver') +, streams +, DateRollingFileStream , testTime = new Date(2012, 8, 12, 10, 37, 11); +if (semver.satisfies(process.version, '>=0.10.0')) { + streams = require('stream'); +} else { + streams = require('readable-stream'); +} +DateRollingFileStream = require('../../lib/streams').DateRollingFileStream + function cleanUp(filename) { return function() { fs.unlink(filename); diff --git a/test/streams/rollingFileStream-test.js b/test/streams/rollingFileStream-test.js index 140be17..73de936 100644 --- a/test/streams/rollingFileStream-test.js +++ b/test/streams/rollingFileStream-test.js @@ -3,8 +3,16 @@ var vows = require('vows') , assert = require('assert') , events = require('events') , fs = require('fs') -, streams = require('stream') -, RollingFileStream = require('../../lib/streams').RollingFileStream; +, semver = require('semver') +, streams +, RollingFileStream; + +if (semver.satisfies(process.version, '>=0.10.0')) { + streams = require('stream'); +} else { + streams = require('readable-stream'); +} +RollingFileStream = require('../../lib/streams').RollingFileStream; function remove(filename) { try {