PC Review


Reply
Thread Tools Rate Thread

Any fast way to determine if a file has been compressed?

 
 
nickdu
Guest
Posts: n/a
 
      22nd Sep 2009
I'm using the deflate stream to compress a file. Is there an easy (/fast)
way for me to detect that this file has been compressed using the deflate
stream? The reason I'm looking for this efficient method of checking whether
a file has been compressed is that I have a current application which is
working with uncompressed files. Ideally I would like to modify the
application to be able to work with both compressed and uncompressed files.
--
Thanks,
Nick

(E-Mail Removed)am
remove "nospam" change community. to msn.com
 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      22nd Sep 2009
On Tue, 22 Sep 2009 07:33:01 -0700, nickdu <(E-Mail Removed)>
wrote:

> I'm using the deflate stream to compress a file. Is there an easy
> (/fast)
> way for me to detect that this file has been compressed using the deflate
> stream? The reason I'm looking for this efficient method of checking
> whether
> a file has been compressed is that I have a current application which is
> working with uncompressed files. Ideally I would like to modify the
> application to be able to work with both compressed and uncompressed
> files.


My recollection is that gzip files (like many file formats) start with a
specific signature byte sequence. So you could always open the file and
look for that.

That said, when I've written code to handle both compressed and
uncompressed data, I simply write the code to always try to uncompress the
file first, and then if that fails, to try to read it as uncompressed
data. I've never had any performance problems with that approach; the
file i/o itself, which is unavoidably, dwarfs any overhead in the code in
terms of performance cost. And doing it that way means you never have to
worry about the exact format of a gzip stream; the compression class
handles all that.

Pete
 
Reply With Quote
 
 
 
 
nickdu
Guest
Posts: n/a
 
      22nd Sep 2009
Thanks. Sounds like a reasonable suggestion. However, do I have to switch
to using the gzip stream then instead of the deflate stream?
--
Thanks,
Nick

(E-Mail Removed)am
remove "nospam" change community. to msn.com


"Peter Duniho" wrote:

> On Tue, 22 Sep 2009 07:33:01 -0700, nickdu <(E-Mail Removed)>
> wrote:
>
> > I'm using the deflate stream to compress a file. Is there an easy
> > (/fast)
> > way for me to detect that this file has been compressed using the deflate
> > stream? The reason I'm looking for this efficient method of checking
> > whether
> > a file has been compressed is that I have a current application which is
> > working with uncompressed files. Ideally I would like to modify the
> > application to be able to work with both compressed and uncompressed
> > files.

>
> My recollection is that gzip files (like many file formats) start with a
> specific signature byte sequence. So you could always open the file and
> look for that.
>
> That said, when I've written code to handle both compressed and
> uncompressed data, I simply write the code to always try to uncompress the
> file first, and then if that fails, to try to read it as uncompressed
> data. I've never had any performance problems with that approach; the
> file i/o itself, which is unavoidably, dwarfs any overhead in the code in
> terms of performance cost. And doing it that way means you never have to
> worry about the exact format of a gzip stream; the compression class
> handles all that.
>
> Pete
>

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      22nd Sep 2009
=?Utf-8?B?bmlja2R1?= <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> I'm using the deflate stream to compress a file. Is there an easy
> (/fast) way for me to detect that this file has been compressed using
> the deflate stream? The reason I'm looking for this efficient method
> of checking whether a file has been compressed is that I have a
> current application which is working with uncompressed files. Ideally
> I would like to modify the application to be able to work with both
> compressed and uncompressed files.


The headers of files have information about the file. You examine the bytes
to the first null char { (char) 0 }. Every compressed file I have seen has
a header that indicates the file type. The same is true of files like
images file, etc.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      23rd Sep 2009
On Tue, 22 Sep 2009 10:33:01 -0700, nickdu <(E-Mail Removed)>
wrote:

> Thanks. Sounds like a reasonable suggestion. However, do I have to
> switch
> to using the gzip stream then instead of the deflate stream?


You should be able to apply the same approach to either class.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fast processor, fast memory and fast graphics but crap Windows smooth scroll beemer Windows XP General 11 14th Nov 2008 11:05 AM
I NEED HELP FAST FAST FAST =?Utf-8?B?QW1hem9uU2FtdXJhaQ==?= Windows XP Performance 3 24th Jul 2006 01:07 AM
Looking for eloquent solution: Determine of any control on a page of multipage has been altered (userform) KR Microsoft Excel Programming 0 13th Dec 2004 10:04 PM
Is there a way to determine if an app has been "minimized"? =?Utf-8?B?UmFscGggRmxhdWdoZXI=?= Microsoft Dot NET Compact Framework 4 13th Apr 2004 08:39 PM
Is there a way to determine if a form has been minimized? =?Utf-8?B?UmFscGggRmxhdWdoZXI=?= Microsoft Dot NET Compact Framework 3 8th Apr 2004 03:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:32 AM.