The Linux Community Forum

Tech Zone => Programming => Topic started by: Mad Penguin on July 30, 2013, 04:25:57 pm

Title: Data compression from Google ...
Post by: Mad Penguin on July 30, 2013, 04:25:57 pm
There's quite a nice compression library called "snappy" knocking about on Google code for anyone who's looking for something pretty quick to compress / decompress data in their code, here's the URL; https://code.google.com/p/snappy/ (https://code.google.com/p/snappy/)

To Compress;

Code: [Select]
  char inp_buf[4096];
  char out_buf[5200];  // watch this, compressed data 'can' be larger than the raw data!
  size_t inp_len = sizeof(inp_buf);
  size_t out_len = sizeof(out_buf);

  snappy_status status = snappy_compress(inp_buf,inp_len,out_buf,&out_len);
  if( status != SNAPPY_OK ) printf("** Compression Error! (%d)\n",status);
And to deCompress;

Code: [Select]
  char inp_buf[5200];
  char out_buf[4096];
  size_t inp_len = sizeof(inp_buf);
  size_t out_len = sizeof(out_buf);

  snappy_status status = snappy_uncompress(inp_buf,inp_len,out_buf,&out_len);
  if( status != SNAPPY_OK ) printf("** deCompression Error! (%d)\n",status);
Should be able to compress around 250Mb/sec and decompress at around 500Mb/sec on a modern processor. Empty 4k blocks compress by as much as 20:1, but on average uncompressed data gives better than 2:1 which isn't a bad saving .. :) .. After messing around with other libraries I was fairly impressed by how clean the implementation is and how easy it is to slot into existing code.
Title: Re: Data compression from Google ...
Post by: davidmichaels on November 07, 2018, 09:47:00 am
wow it seems interesting and curious at the same time.
SimplePortal 2.3.3 © 2008-2010, SimplePortal