Note that there are some explanatory texts on larger screens.

plurals
  1. PODecompress compressed string with Huffman algorithm
    text
    copied!<p>I am trying to use Huffman algorithm from <a href="http://www.explainth.at/downloads/huff.zip" rel="nofollow">http://www.explainth.at/downloads/huff.zip</a></p> <p>There are two function in the unit :</p> <p>function Compress(ASource:TMemoryStream):TMemoryStream;<br> function DeCompress(ASource:TMemoryStream):TMemoryStream;</p> <p>I've successfully compressed each lines from a file onto an another file.</p> <pre><code>function StreamToString(const stream: TStream) : string; var Size: Integer; begin result:=''; Size := Stream.Size - Stream.Position; SetString(result, nil, Size); Stream.Read(Pointer(result)^, Size); end; procedure TMaster.Button1Click(Sender: TObject); var list,list_:TStringlist; AStream:TMemoryStream; BStream:TMemoryStream; s:string; i,j:integer; begin list := TStringList.Create; list_:= TStringList.Create; list.LoadFromFile('d:\input.txt'); for j := 0 to List.Count - 1 do begin s:=list[j]; if (Length(s) = 0) then exit; {i:=Pos(#13#10,s); while (i &gt; 0) do begin Delete(s,i,2); i:=Pos(#13#10,s); end;} AStream:=TMemoryStream.Create; with AStream do WriteBuffer(s[1],Length(s)); with THuffman.Create do try BStream:=Compress(AStream); finally Free; AStream.Free; end; with THuffman.Create do try AStream:=ProcessToDecrypt (BStream); list_.Add(StreamToString(BStream)); finally BStream.Free; end end; //for j := 0 to List.Count - 1 do list_.SaveToFile('d:\output.txt'); list_.free; list.free; end; function THuffman.ProcessToDecrypt(ASource:TMemoryStream):TMemoryStream; var ASize:Integer; begin ASize:=ReBuildTree(ASource); exit; end; </code></pre> <p>I also want to decompress each compressed line from a file to string. </p> <p>Here's what I done to decompress the string </p> <pre><code>procedure TMaster.Button2Click(Sender: TObject); var i:Integer; AText:String; AStream:TMemoryStream; BStream:TMemoryStream; begin AText:='È1ëz-'; BStream:=TMemoryStream.Create; with BStream do WriteBuffer(AText[1],Length(AText)); with THuffman.Create do try AStream:=ProcessToDecrypt (BStream); AStream:=Decompress(BStream); memoOut.Lines.add.StreamToString(BStream); finally BStream.Free; end; end; </code></pre> <p>Button2Click procedure doesn't work. <s>The short question is how do I decompress the compressed <strong>string</strong>?</s></p> <p>The parameter of DeCompress is TMemoryStream, <s>How do I use a string as the parameter?</s><br> How to make the output of DeCompress as string?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload