Permalink
Browse files

- problem with scoping

  • Loading branch information...
1 parent 726145d commit e084b54fe57b736a269a0862c33368e94e69bc77 @dennisoelkers committed Dec 8, 2011
Showing with 15 additions and 11 deletions.
  1. +15 −11 lib/gelf.js
View
@@ -4,18 +4,9 @@ var zlib = require('zlib');
var Binary = require('binary');
function decode(buf) {
- var gelf_header = Binary.parse(buf).word16lu('chunk_magic').vars;
- var json;
- switch(gelf_header['chunk_magic']) {
- case '40056':
- json = zlib.inflate(buf);
- break;
- case '35615':
- logger.error('got GZIP message, trying to unzip');
- json = zlib.Gunzip(buf);
- break;
- }
+ var json = uncompress(buf);
+ logger.error('got json: '+json);
return JSON.parse(json);
}
@@ -28,5 +19,18 @@ function encode(struc) {
return comp;
}
+function uncompress(buf) {
+ var gelf_header = Binary.parse(buf).word16lu('chunk_magic').vars;
+ switch(gelf_header['chunk_magic']) {
+ case '40056':
+ return zlib.inflate(buf);
+ break;
+ case '35615':
+ logger.error('got GZIP message, trying to unzip');
+ return zlib.Gunzip(buf);
+ break;
+ }
+}
+
exports.decode = decode;
exports.encode = encode;

0 comments on commit e084b54

Please sign in to comment.