Loading...

How do I calculate size of a compressed object?


How do I calculate the actual size of a object or compressed object(Bytes) in javascript,and not based on length of characters in the object?

I tried object-sizeof npm library,but it returns size based on length of characters.In the below code jsonCompressCheck is a large Json Object which I need to compress and I want to get the sizes so that I know how efficient it is

console.log("Actual Object Size: "+sizeof($scope.jsonCompressCheck));
var zlib = require('zlib');
var sizeof = require('object-sizeof');
  zlib.deflate(JSON.stringify($scope.jsonCompressCheck),function(err, buffer) {
            if (!err) {
              console.log("USing Deflate Size of: ");
              console.log("Byte Length: "+Buffer.byteLength(buffer));
              console.log(sizeof(buffer));
             $scope.compressed = buffer;
            }
          });
     zlib.gzip(JSON.stringify($scope.jsonCompressCheck),function(err, buffer) {
            if (!err) {
              console.log("USing gzip: ");
              console.log("Byte Length: "+Buffer.byteLength(buffer));
              console.log(sizeof(buffer));
             $scope.compressed = buffer;
            }
          });   
- - Source
comments powered by Disqus