var Types = require("../common/Types.js");
var compress = require('compress-buffer').compress;
var uncompress = require('compress-buffer').uncompress;



var Compressor = function(configuration){
    this._configuration = configuration;
};
    
Compressor.prototype.compress = function(data, callback, compressLevel){
    compressLevel = compressLevel || 6;
    var compressedData = compress(data, compressLevel);
    callback(
        compressedData,
        this._getCompressionRate(data.length, compressedData.length)
    );
};

Compressor.prototype.uncompress = function(data, callback){
    var compressedData = uncompress(data);
    callback(
        compressedData,
        this._getCompressionRate(compressedData.length, data.length)
    );
}


Compressor.prototype._getCompressionRate = function(unCompressedLength, compressedLength){
    return {
        times: Math.round(unCompressedLength/compressedLength),
        percentage: Math.round((100-(100*(compressedLength/unCompressedLength)))),
        compressedLength: compressedLength,
        unCompressedLength: unCompressedLength
    };        
};
    

exports.Compressor = Compressor;    
