Tech Zone > Programming

Data compression from Google ...

(1/1)

Mad Penguin:
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/

To Compress;


--- Code: ---
  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);
--- End code ---
And to deCompress;


--- Code: ---
  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);
--- End code ---
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.

davidmichaels:
wow it seems interesting and curious at the same time.

Navigation

[0] Message Index

Go to full version