سؤال

I need some way to determine if a file is compressed in some kind of extension ex:(rar, tar, tar.gz, etc.), it is using C/C++ languages under linux systems. I read something about stat and S_IFCMP, but I can't use it in linux, so, can you help me with some alternative?

هل كانت مفيدة؟

المحلول

There is no bullet proof way to determine this. You can check the extension. If you don't trust the extension, then you have to look into the file and check for signatures.

You can find some of them here.

The call to stat will not tell you about individual files being compressed, as this flag means that the file system is compressed.

نصائح أخرى

Each file format have its own signature. There is no generic way that can be applied to all compressed file formats like RAR,TAR,TAR.GZ. Signature for various file formats is avialable at: http://www.garykessler.net/library/file_sigs.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top