home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tplzh025.zip / TESTLZO.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-23  |  3KB  |  110 lines

  1. {$A+,B-,D+,E+,F+,I-,L-,N-,O-,R-,S-,V-}
  2. {$M 2048,60000,60000}
  3.  
  4. program LZOTest;
  5.  
  6. uses
  7.   LZO;
  8.  
  9. type TFileHuff = Object (THuff)
  10.        infile, outfile: file;
  11.        counter: longint;
  12.        constructor Init (infname, outfname: String);
  13.        destructor  Done; virtual;
  14.        function    ReadBuf (var data; size: word): longint; virtual;
  15.        function    WriteBuf (var data; size: word): longint; virtual;
  16.      END;
  17.  
  18.  
  19. constructor TFileHuff.Init (infname, outfname: String);
  20. begin
  21.   THuff.Init;
  22.   Assign (infile, infname);
  23.   Reset (infile, 1);
  24.   if IoResult > 0 then begin
  25.     Writeln ('! Can''t open input file'); Halt (1)
  26.   end;
  27.   Assign (outfile, outfname);
  28.   Rewrite (outfile, 1);
  29.   if IoResult > 0 then begin
  30.     Writeln ('! Can''t open input file'); Halt (1)
  31.   end;
  32.   counter := 0
  33. end;
  34.  
  35. destructor TFileHuff.Done;
  36. begin
  37.   Close (infile);
  38.   if IoResult>0 then begin
  39.     Writeln ('! Error closing input file'); Halt (1)
  40.   end;
  41.   Close (outfile);
  42.   if IoResult>0 then begin
  43.     Writeln ('! Error closing output file'); Halt (1)
  44.   end;
  45. end;
  46.  
  47. function TFileHuff.ReadBuf (var data; size: word): longint;
  48. var rd: word;
  49. begin
  50.   BlockRead (infile, data, size, rd);
  51.   if IOResult > 0 then
  52.     ReadBuf := -1
  53.   else
  54.     ReadBuf := rd;
  55.   if Compressing then begin
  56.     inc (counter, rd);
  57.     Write (counter, #13)
  58.   end;
  59. end;
  60.  
  61. function TFileHuff.WriteBuf (var data; size: word): longint;
  62. var wr: word;
  63. begin
  64.   BlockWrite (outfile, data, size, wr);
  65.   if IOResult > 0 then
  66.     WriteBuf := -1
  67.   else
  68.     WriteBuf := wr;
  69.   if not Compressing then begin
  70.     inc (counter, wr);
  71.     Write (counter, #13)
  72.   end;
  73. end;
  74.  
  75. var
  76.   s: String;
  77.   test: Word;
  78.   RData: Byte;
  79.   FileHuff: TFileHuff;
  80.   fsize,
  81.   compr: longint;
  82.  
  83. begin
  84.   Writeln ('Huffman Compression Engine v', EngineVer);
  85.   if ParamCount <> 3 then begin
  86.     Writeln ('Usage: testlzo e(ncode)|d(ecode) infile outfile');
  87.     Halt (1);
  88.   end;
  89.  
  90.   FileHuff.Init (ParamStr (2), ParamStr (3));
  91.  
  92.   s := ParamStr(1);
  93.   case s[1] of
  94.    'e','E': Begin
  95.               fsize := FileSize (FileHuff.infile);
  96.               Writeln (fsize);
  97.               compr := FileHuff.Compress (fsize);
  98.  
  99.               Writeln ('input:  ', fsize, ' bytes');
  100.               Writeln ('output: ', compr, ' bytes');
  101.               Writeln ('relative output: ', compr*100 div fsize, '%');
  102.             End;
  103.    'd','D': FileHuff.Expand
  104.    else begin
  105.           Writeln ('! Use [D] for Decompression or [E] for Compression');
  106.           Halt (1)
  107.         end;
  108.   end;
  109.   FileHuff.Done;
  110. end.