How can we know the size of a compressed file? 
Author Message
 How can we know the size of a compressed file?

With the Mico$oft LZEXPAND.DLL you may expand files compressed with
COMPRESS.EXE. API is given by BORLAND (thanx).

Nice! But how can we know the size a file will occupy BEFORE decom-
pressing it with the LZEXPAND.DLL. A brutal method would be :
1/decompress it
2/get its size thru appropriate function.
This is awkward, and I wonder if there is some documentation on
the structure of compressed files that can give me the desired
information: the real size.

Now, it's your turn!

Regards.
+++ Yves VAGANAY http://www.*-*-*.com/
+++ FRANCE TELECOM CNET - PAB/RGF/RCS 3 ave. de la Republique
+++ 92131 ISSY-LES-MOULINEAUX FRANCE
+++ "Moin k'a pas vend'chat dans sac!"



Wed, 18 Jun 1902 08:00:00 GMT  
 How can we know the size of a compressed file?

Quote:
> With the Mico$oft LZEXPAND.DLL you may expand files compressed with
> COMPRESS.EXE. API is given by BORLAND (thanx).

> Nice! But how can we know the size a file will occupy BEFORE decom-
> pressing it with the LZEXPAND.DLL. A brutal method would be :
> 1/decompress it
> 2/get its size thru appropriate function.
> This is awkward, and I wonder if there is some documentation on
> the structure of compressed files that can give me the desired
> information: the real size.

   This may not be enough for you, but attached is TP/BP code which
"walks" through a .LZH file and collects all the information about it.  
You may be able to use some of the code to obtain what you want.  (Note
that .ARC file processing is also shown...)
   Hope it helps you.  8<}}

[ MAX3 3K ]
(**************************** ARC Files Processing ***************************)
Type ARCHead = record
                 ARCMark   : char;
                 ARCVer    : Byte;
                 FN        : array[1..13] of char;
                 CompSize  : LongInt;
                 DOS_DT    : LongInt;
                 CRC       : Word;
                 UCompSize : LongInt;
               end;
const ARCFlag : char = #26;                                        { ARC mark }
Var WLV   : LongInt;                               { Working LongInt Variable }
    ARC1  : ARCHead;
    QUIT  : boolean;                             { "end" sentinel encountered }

procedure GET_ARC_ENTRY;
begin
  FillChar(ARC1,SizeOf(ARCHead),#0); L := SizeOf(ARCHead);
  Seek (F,C); BlockRead (F,BUFF,L,RES);
  Move (BUFF[1],ARC1,L);
  with ARC1 do
    if (ARCMark = ARCFlag) and (ARCVer > 0) then
      begin
        SNAME := ''; I := 1;
        while FN[I] <> #0 do
          begin
            SNAME := SNAME+FN[I]; Inc(I)
          end;
        WLV := (DOS_DT Shr 16)+(DOS_DT Shl 16);              { flip Date/Time }
        FSize := CompSize;
      end;
    QUIT := ARC1.ARCVer <= 0;
end;  { GET_ARC_ENTRY }

procedure DO_ARC (FN : string);
begin
  ADD_ANAME; Assign (F,FN); Reset (F,1); C := 0;
  repeat
    GET_ARC_ENTRY;
    if not QUIT then
      begin
        Inc (WPX); New(SW[WPX]);       { store filename info in dynamic array }
        with SW[WPX]^ do
          begin
            FSplit (SNAME,DIR,FNAME,EXT); F := FNAME; E := Copy(EXT+'    ',1,4);
            SIZE := ARC1.UCompSize; RTYPE := 4;                   { comp file }
            D_T := WLV; ANUM := ADX; VNUM := VDX;
            ADD_CNAME;
          end;
        Inc (CCT); SSL; Inc (ARCS[ADX]^.COUNT)
      end;
    Inc (C,FSize+SizeOf(ARCHead))
  until QUIT;
  Close (F);
end;  { DO_ARC }

(************************* LZH Files Processing ******************************)
Type LZHHead = record
                 HSize       : Byte;
                 Fill1       : Byte;
                 Method      : array[1..5] of char;
                 CompSize    : LongInt;
                 UCompSize   : LongInt;
                 DOS_DT      : LongInt;
                 Fill2       : Word;
                 FileNameLen : Byte;
                 FileName    : array[1..12] of char;
               end;

Var LZH1     : LZHHead;

procedure GET_LZH_ENTRY;
begin
  FillChar(LZH1,SizeOf(LZHHead),#0); FillChar (DT,SizeOf(DT),#0);
  L := SizeOf(LZHHead);
  Seek (F,C); BlockRead (F,BUFF,L,RES);
  Move (BUFF[1],LZH1,L);
  with LZH1 do
    if HSize > 0 then
      begin
        Move (FileNameLen,SNAME,FileNameLen+1);
        UnPackTime (DOS_DT,DT);
        FSize := CompSize;
      end
    else QUIT := true
end;  { GET_LZH_ENTRY }

procedure DO_LZH (FN : string);
begin
  ADD_ANAME; Assign (F,FN); Reset (F,1);
  FSize := FileSize(F); C := 0; QUIT := false;
  repeat
    GET_LZH_ENTRY;
    if not QUIT then
      begin
        Inc (WPX); New(SW[WPX]);       { store filename info in dynamic array }
        with SW[WPX]^ do
          begin
            FSplit (SNAME,DIR,FNAME,EXT); F := FNAME; E := Copy(EXT+'    ',1,4);
            SIZE := LZH1.UCompSize;
            RTYPE := 4; ANUM := ADX; VNUM := VDX; D_T := LZH1.DOS_DT;
            ADD_CNAME;
          end;
        Inc (CCT); SSL; Inc (ARCS[ADX]^.COUNT)
      end;
    Inc (C,FSize+LZH1.HSize+2)
  until QUIT;
  Close (F);
end;  { DO_LZH }



Wed, 18 Jun 1902 08:00:00 GMT  
 How can we know the size of a compressed file?


so many thanks Mike,

but,

I think this did not answer my question which has to
do with the Microsoft's COMPRESS.EXE utility and its partner
LZEXPAND.DLL (and also the similar EXPAND.EXE Dos utility).

What I need is the actual format of files compressed through this
utility, or more precisely "Is there an _explicit_ method to guess
what size a file will occupy WITHOUT HAVING to LZEXPAND it under
Ms Windows".

Usually files COMPRESSed by this Microsoft utility have the naming
convention:

compressed       real name
============     ============
DOSMTHNG.EX_ for DOSMTHNG.EXE
MANUAL.DO_   ... MANUAL.DOC
etc...
You find such files in Setup's sets of files for instance.
I need the info in order to evaluate the size needed on disks
or for estimating the needed disk capacity in processes where
files are expanded after -for instance- transmission.

Think all is said. e-mail for longer discussion.

Regards.
+++ Yves VAGANAY http://www.cnet.fr
+++ FRANCE TELECOM CNET - PAB/RGF/RCS 3 ave. de la Republique
+++ 92794 ISSY-MOULINEAUX CEDEX 9 - FRANCE
+++ "Moin k'a pas vend'chat dans sac!"



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to know...(stuf about Microsoft compressed files)

2. Converting binary (text file) to compress binary file

3. Converting ASCII Text file to compress binary file format

4. Get file attributes of compressed files

5. It's not bad canned meat...

6. compress mdb file

7. File Compressing Help

8. Playing WAV files compressed with Creative ADPCM or Microsft ADPCM

9. Recording Compressed WAV files

10. How to get attributes of compressed files

11. Compressing files

12. need TPW algorithms for compressing files

 

 
Powered by phpBB® Forum Software