Example #1
0
 }, function(err, res, body) {
   res.headers['content-type'].should.startWith('text/plain');
   res.headers['content-encoding'].should.eql('gzip');
   zlib.gunzip(body, function(zerr, result) {
     result.toString().should.eql("What's a truck?\n");
     done(err || zerr);
   });
 });
Example #2
0
 analytics.spi.send = function send(compressed) {
   var zlib = require('zlib');
   zlib.gunzip(compressed, function(err, uncompressed) {
     var data = JSON.parse(uncompressed);
     recordsQueue.should.eql(data.records);
     done();
   });
 };
Example #3
0
function gunzip(object, callback) {
    var buffer = new Buffer(object.Body);
    console.log('Unzipping CloudTrail archive');
    zlib.gunzip(buffer, function(err, decoded) {
        if (!err) console.log('Message unzipped successfully')
        callback(err, decoded && decoded.toString());
    });
}
Example #4
0
File: db.js Project: radare/bugcoin
	fs.readFile (database+".gz", function (err, data) {
		zlib.gunzip (data, function (err, str) {
			try {
				store = JP (str);
			} catch (e) {
			}
		});
	});
Example #5
0
				}).on('end', () => {
					if (encoding === 'deflate') {
						zlib.inflate(body, decompress);
					} else if (encoding === 'gzip') {
						zlib.gunzip(body, decompress);
					} else {
						this.emit('body', response, body);
					}
				});
Example #6
0
     function (er, res, body) {
   t.equal(res.statusCode, 200)
   t.equal(res.headers['content-encoding'], 'gzip')
   zlib.gunzip(body, function (er, body) {
     if (er) throw er;
     t.equal(body.toString(), stExpect)
     t.end()
   })
 })
Example #7
0
    return new Promise((resolve, reject) =>
    {
        zlib.gunzip(buffer, (err, data) =>
        {
            if (err) return reject(err);

            resolve(data);
        });
    });
Example #8
0
ServerResponseWrapper.prototype.decompress = function(buffer, callback) {
  if (this.headers['content-encoding'] === 'gzip') {
    zlib.gunzip(buffer, callback);
  } else if (this.headers['content-encoding'] === 'deflate') {
    zlib.inflate(buffer, callback);
  } else {
    throw new Error('Invalid encoding: ' + this.headers['content-encoding']);
  }
};
 function(err, contents) {
   contents.toString('utf8').should.eql('This is the third log message.\n');
   zlib.gunzip(fs.readFileSync(path.join(__dirname, testFiles[2])),
     function(err, contents) {
       contents.toString('utf8').should.eql('This is the second log message.\n');
       done(err);
     }
   );
 }
Example #10
0
    res.on('end', function () {
      if (res.statusCode != 200) {
        return callback([res.statusCode, url], body.toString());
      }
      if (res.headers['content-encoding'] == 'gzip')
        return zlib.gunzip(body, callback)

      callback(null, body);
    })
 return new Promise((resolve, reject) => {
   zlib.gunzip(zippedContent, (err, result) => {
     if (err) {
       reject(err);
     } else {
       resolve(JSON.parse(result.toString()));
     }
   });
 });
Example #12
0
 zlib.gzip(str, function(e,b) {
   expect(e).toBeFalsy();
   expect(b.toString('base64')).toBe(encoded);
   zlib.gunzip(b, function(ee, bb) {
     expect(ee).toBeFalsy();
     expect(bb.toString()).toBe(str);
     helper.testComplete(true);
   });
 });
		fs.readFile(cacheFile, function(err, buf) {
			if (/\.gz$/.test(cacheFile)) {
				zlib.gunzip(buf, function(err, buf) {
					return callback(null, JSON.parse(String(buf)));
				});
			} else {
				return callback(null, JSON.parse(String(buf)));
			}
		});
Example #14
0
 function do_gunzip(cb) {
   if (err) return cb()
   if (res.headers['content-encoding'] !== 'gzip') return cb()
   zlib.gunzip(body, function(er, buf) {
     if (er) err = er
     body = buf
     return cb()
   })
 }
Example #15
0
 res.on('finish', function () {
   var buffer = Buffer.concat(buffers);
   isGzip ?
     zlib.gunzip(Buffer.concat(buffers), function (err, buffer) {
       if (err) return;
       writeCgi(buffer, req.url, ~proxyReq.headers['content-type'].indexOf('application/json'));
     }) :
     writeCgi(buffer, req.url, ~proxyReq.headers['content-type'].indexOf('application/json'));
 });
Example #16
0
 fs.readFile(file, function (err, data) {
   fs.unlink(file, function () {});
   if (err) throw new Error(err);
   zlib.gunzip(data, {chunkSize: 65536}, function (err, data) {
     if (err) throw new Error(err);
     msg.req.args = data;
     runTask(msg);
   });
 });
Example #17
0
function unzip(buffer) {
  return zlib.gunzip(buffer, (err, buffer) => {
    if (!err) {
      console.log(buffer.toString());
    } else {
      console.log(err.toString());
    }
  });
}
Example #18
0
	decompress = function (data, encoding, callback) {
		if (encoding === 'gzip') {
			zlib.gunzip(data, callback);
		} else if (encoding === 'deflate') {
			zlib.inflate(data, callback);
		} else {
			callback(null, data);
		}
	},
Example #19
0
 proxyResponse.on('end', function() {
   if (!shouldBuffer) {
     try {
       response.end();
     } catch (error) {
       emitter.emit('error', error, 'proxyResponseError', requestInfo);
     }
     
     emitter.emit('completeUnfitered');
     return;
   }
   
   var match = (proxyResponse.headers['content-type'] || '').match(/charset=([^;]+)/);
   var charset = (match ? match[1] : null);
   
   var writeResponse = function(outputBuffer) {
       var encoding = recompress ? responseEncoding : undefined;
       var writeOutput = function(error, b) {
           if (error) {
             emitter.emit('error', error, 'recompressing', requestInfo);
           }
           response.end(b);
       };
       switch (encoding) {
       case 'gzip':
         zlib.gzip(outputBuffer, writeOutput);
         break;
       case 'deflate':
         zlib.deflate(outputBuffer, writeOutput);
         break;
       default:
         writeOutput(null, outputBuffer);
       }
   };
   
   var setupIntercept = function(error, newBuffer) {
       if (error) {
         emitter.emit('error', error, 'decompressing', requestInfo);
       }
       emitOrRun('interceptResponseContent', function() {
         writeResponse(newBuffer);
       }, newBuffer, proxyResponse, isSsl, charset, response, writeResponse);
   };
   
   buffer = Buffer.concat(buffers, bufferLength);
   switch (responseEncoding) {
   case 'gzip':
     zlib.gunzip(buffer, setupIntercept);
     break;
   case 'deflate':
     zlib.inflate(buffer, setupIntercept);
     break;
   default:
     setupIntercept(null, buffer);
   }
 });
Example #20
0
	it("gzipTo (from Stream)", function() {
		var stm = new io.MemoryStream();
		stm.write(b);

		stm.rewind()
		var stm1 = new io.MemoryStream();
		zlib.gzipTo(stm, stm1);
		stm1.rewind();
		assert.equal(zlib.gunzip(stm1.read()).toString(), b.toString());
	});
Example #21
0
            res.on('end', function () {
                var buffer = Buffer.concat(chunks);

                //Decompress
                zlib.gunzip(buffer, function (err, decoded) {
                    sub.data = decoded;
                    sub.isDownloaded = true;
                    cb(decoded);
                });
            });
Example #22
0
function unpack(buff, cb) {
	zlib.gunzip(buff, function(err, res) {
		if (err) {
			cb(err);
			return;
		}
		var obj = msgpack.unpack(res);
		cb(null, obj);
	});
}
Example #23
0
    it("gzipTo (from Stream)", () => {
        var stm = new io.MemoryStream();
        stm.write(b);

        stm.rewind()
        var stm1 = new io.MemoryStream();
        zlib.gzipTo(stm, stm1);
        stm1.rewind();
        assert.deepEqual(zlib.gunzip(stm1.readAll()), b);
    });
Example #24
0
DataReader.openGz = function(buffer, callback) {
    console.log("In openGz!");
    zlib.gunzip(buffer, function(err, decoded) {
        if (err) {
        } else {
            raw = decoded.toString();
            callback(raw);
        }
    });
};
Example #25
0
 it('should gunzip a file', function() {
   waitsFor(helper.testComplete, 'the test to complete', 8000);
   var fs = require('fs');
   var buf = fs.readFileSync(__dirname + "/zlibFixture.txt.gz");
   zlib.gunzip(buf, function(e, b) {
     expect(e).toBeFalsy();
     expect(b.toString()).toBe("This is a test file for zlib\n");
     helper.testComplete(true);
   });
 });
Example #26
0
	raw = fs.readFile(filepath, function(err, gzcontent){
		zlib.gunzip(gzcontent, function(err, content){
			content = content + '';
			for(i in oldSitePatterns){
				var reg = oldSitePatterns[i];
				content = content.replace(reg, function($0, $1){;return newSite + $1;});
			}
			res.send(content);
		});
	});
 zlib.gunzip(s3results[0].Body, function(err, first) {
     assert.ifError(err, 'gzipped backup');
     zlib.gunzip(s3results[1].Body, function(err, second) {
         assert.ifError(err, 'gzipped backup');
         first = first.toString().trim().split('\n');
         second = second.toString().trim().split('\n');
         assert.equal(first.length + second.length, 1000, 'backed up all records');
         assert.end();
     });
 });
	return new Promise((res, rej) => {
		zlib.gunzip(buffer, function (error, data) {
			if(error) return rej(error);

			// Do the actual parsing
			var table = new LuaParser(data).parse();

			res(table);
		});
	});
Example #29
0
 request(opt, function (error, response, body) {
     if(response.headers['content-encoding'] == 'gzip'){
         //console.log(response.headers);
         zlib.gunzip(response.body, function(err, dezipped){
             res.send(dezipped);
         });
     } else {
         res.send(body);
     }
 });
Example #30
0
 .on("end", function () {
   body = Buffer.concat(body);
   if (resp.headers['content-encoding'] === 'gzip') {
     zlib.gunzip(body, function (err, data) {
       console.log(data.toString("UTF-8"));
     })
   } else {
     console.log(body.toString());
   }
 });