Click here to Skip to main content
13,665,017 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

17.5K views
249 downloads
13 bookmarked
Posted 16 Feb 2015
Licenced CPOL

The Compression API: It was about time

, 16 Feb 2015
Rate this:
Please Sign up or sign in to vote.
The ability to compress/decompress data in Win32

Introduction

I guess it is too late, but they finally put it. A compression/decompression api in windows which is easy to use. And, with my class, even easier.

Background

The API is a simple set of functions that allow compression or decompression of data.  Windows supports a number of algorithms (https://msdn.microsoft.com/en-us/library/windows/desktop/hh920921(v=vs.85).aspx) which we can select in our constructor. Windows also supports block-mode, if you want to control the compressor, which is not a feature in our quick class.

Because the API exists only in Windows 8, all our class calls are dynamic (incidentally, the call uses the template from my One-Line call article) . You can check the static member COMPRESSIONAPI::Available() to see if the API is available.  If the API is not available, constructing the object will throw.

Using the code

 

//
    if (!COMPRESSIONAPI::Available())
        BlowThisPC(); // :)
   
    COMPRESSIONAPI c(COMPRESS_ALGORITHM_LZMS);
   
    vector<char> x;
    x.resize(10000);
    strcpy_s(x.data(),10000,"Hello there");
   
    vector<char> rs;
    c.Compress(x.data(),10000,rs);

    vector<char> rs2;
    c.Decompress(rs.data(),rs.size(),rs2);

//

 

Easy. You have the constructor (which specifies the compression algorithm, in this case COMPRESS_ALGORITHM_LZMS.  Then you have 2 member functions, Compress and Decompress. Both take the buffer to work on, it's size, and a vector<char> to put the result. They return S_OK on success and E_FAIL on error.

Internally, my class tests the API in order to find out the exact size neeeded for the buffer. 

History

16 - 2 - 2015 : First Release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael Chourdakis
Engineer
Greece Greece
I'm working in C++, PHP , Java, Windows, iOS and Android.

I 've a PhD in Digital Signal Processing and I specialize in Pro Audio applications.

My home page: http://www.michaelchourdakis.com

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 3 Pin
Cristian Amarie16-Feb-15 3:46
memberCristian Amarie16-Feb-15 3:46 
GeneralRe: My vote of 3 Pin
Michael Chourdakis16-Feb-15 3:49
memberMichael Chourdakis16-Feb-15 3:49 
GeneralRe: My vote of 3 Pin
Axel Rietschin10-May-18 6:18
professionalAxel Rietschin10-May-18 6:18 
GeneralRe: My vote of 3 Pin
Cristian Amarie15-May-18 10:56
memberCristian Amarie15-May-18 10:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.180810.1 | Last Updated 16 Feb 2015
Article Copyright 2015 by Michael Chourdakis
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid