{$MODE OBJFPC}
uses
  dtypes,
  dbitstream,
  dlzw_decompressor;

type
TStream = object
  function Read(var Buffer; Count: LongInt): LongInt;
end;

function TStream.Read(var Buffer; Count: LongInt): LongInt;
var
  C: AnsiChar;
  B: PByte;
begin
  Result := 0;
  B := @Buffer;
  while Count > 0 do begin
    if Eof then
      Exit;
    System.Read(C);
	B^ := Byte(C);
	Inc(B);
    Inc(Result);
	Dec(Count);
  end;
end;

var
  Stream: TStream;
  P: Pointer;
  L: LongInt;
  S: AnsiString;

begin
  if LZWDecompress(@Stream.Read, P, L) then begin
    SetString(S, PAnsiChar(P), L);
    Writeln(S);
    FreeMem(P);
  end else
    Writeln('LZW decompressing failed');
end.
