Permalink
Browse files

Merge pull request #28 from ddopson/master

Backcompat Fixes (re: Woodya discussion)
  • Loading branch information...
2 parents 60b1364 + f281c02 commit 396c7f1da6574dcc7c7db741db189858a27341d2 @Woodya Woodya committed Dec 16, 2011
Showing with 13 additions and 6 deletions.
  1. +13 −6 lib/zookeeper.js
View
@@ -51,17 +51,20 @@ function ZooKeeper(config) {
proxyProperty('client_id');
proxyProperty('is_unrecoverable');
- self.encoding = 'utf8';
+ self.encoding = null; // Return 'Buffer' objects by default
self.setEncoding = function setEncoding(val) {
self.encoding = val;
};
+ // Backwards Compat for 'data_as_buffer' property. deprecated. just use setEncoding()
self.__defineGetter__('data_as_buffer', function(){
- return self.encoding ? true : false;
+ // if there's an encoding, then data isn't a buffer. If there's no encoding, then data will be a buffer
+ return self.encoding ? false : true;
});
- self.__defineSetter__('data_as_buffer', function(val){
- self.encoding = ((val == true) ? null : 'utf8');
+ self.__defineSetter__('data_as_buffer', function(data_as_buffer){
+ // if the data is a buffer, then there's no encoding. If the data is NOT a buffer, then the default encoding is 'utf8'
+ self.encoding = ((data_as_buffer == true) ? null : 'utf8');
});
}
@@ -171,10 +174,14 @@ ZooKeeper.prototype.init = function init(config) {
config = config ? _.defaults(config, self.config) : self.config;
}
if(this.logger) this.logger("Calling init with " + util.inspect(arguments));
- if(!_.isUndefined(config.data_as_buffer)) {
+ if(! _.isUndefined(config.data_as_buffer)) {
self.data_as_buffer = config.data_as_buffer;
+ if(this.logger) this.logger("Encoding for data output: %s", self.encoding);
}
- return this._native.init.call(this._native, config);
+ this._native.init.call(this._native, config);
+
+ // The native code returns a ref to itself. So we should return a ref to the wrapper object
+ return self;
}
ZooKeeper.prototype.connect = function connect(options, cb) {

0 comments on commit 396c7f1

Please sign in to comment.