数据压缩 -- 源码[13]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 luckyjan 的 blog

  matchlen := 0;
end;

{******************************** interface procedures ************************}
procedure lhacompress(instr, outstr: tstream);
begin
  initmemory;
  try
    infile := instr;
    outfile := outstr;
    origsize := infile.size - infile.position;
    compsize := 0;
    outfile.write(origsize,4);
    encode;
  finally
    freememory;
  end;
end;

procedure lhaexpand(instr, outstr: tstream);    //解码
begin
  try
    initmemory;
    infile := instr;
    outfile := outstr;
    compsize := infile.size - infile.position;
    infile.read(origsize,4);
    decode;
  finally
    freememory;
  end;
end;

initialization
  clen := nil;
  ctable := nil;
  right := nil;
  left := nil;
  buffer := nil;
  heap := nil;
end.

{******************************** test program ********************************}
{
  the following simple program can be used for testing the lh5unit.
  it compresses/expands files compatible with lharc.
}
program testlh5;

uses
  wincrt,
  sysutils,
  classes,
  lh5unit;

var
  instr, outstr: tfilestream;

begin
  if not (paramcount in [2..3]) then
    begin
      writeln('usage :');
      writeln('to compress infile into outfile : lh5 infile outfile');
      writeln('to expand infile into outfile :   lh5 infile outfile e');
      halt;
    end;
  instr := tfilestream.create(paramstr(1),fmopenread);
  outstr := tfilestream.create(paramstr(2),fmcreate);
  if paramcount=2 then
      lhacompress(instr, outstr)
    else
      lhaexpand(instr, outstr);
  instr.free;
  outstr.free;
end.

本文关键:数据压缩 -- 源码
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top