Archived Forum Post

Index of archived forum posts

Question:

TAR Extract only Files Having a Certain Extension?

Sep 25 '12 at 12:22

I want to see if there is any future plans to add an API to extract only a specific file/ certain extension from the tar without untarring the whole bundle.


Answer

If using programming language that supports callbacks, one possibility is to use the NextTarFile callback to set the "skip" flag for all files except the ones you need to extract. For example, in C++, you have this:

class CkTarProgress : public CkObject 
{
    public:
    CkTarProgress() { }
    virtual ~CkTarProgress() { }

// pathInTar 
virtual void ProgressInfo(const char *name, const char *value) { }

// Called periodically to check to see if the method call should be aborted.
virtual void AbortCheck(bool *abort) { }

// Called just before appending to TAR when writing a .tar, and just before
// extracting during untar.
virtual void NextTarFile(const char *fileName, 
    __int64 fileSize,
    bool bIsDirectory, 
    bool *skip) { }

};

Your app would define a class that derives from CkTarProgress, and then implement the NextTarFile method, overriding the empty implementation in the base class. Your callback method would examine the fileName and set the skip bool equal to true if the file should not be extracted.

The equivalent callback is available w/ the ActiveX, Objective-C, and .NET implementations.