Solved

ZLIB TCompressionstream

Posted on 2000-03-08
2
1,046 Views
Last Modified: 2012-05-04
Does anyone know how to properly use the ZLIB compression streams that come with Delphi 4?

I think it's called TCompressionStream;

Sorry for the low point value, this question isn't a high priority problem and I have a temporary solution for now.
0
Comment
Question by:arcrotty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2598421
you not have the d3 sample?

i post here i case not:

program Test;
 
{$APPTYPE CONSOLE}
 
uses Classes, SysUtils, ZLib;
 
const
  BufferSize = 4096;
 
type
  TTest = class
    InFile: TStream;
    OutFile: TStream;
    ZStream: TCustomZLibStream;
    Buffer: array[0..BufferSize-1] of Byte;
    procedure Expand;
    procedure Shrink;
    procedure Status(Sender: TObject);
  end;
 
procedure TTest.Shrink;
begin
  InFile := TFileStream.Create('test.dpr', fmOpenRead);
  try
 
    OutFile := TFileStream.Create('test.dat', fmCreate);
    try
 
      ZStream := TCompressionStream.Create(clFastest, OutFile);
      try
        TCompressionStream(ZStream).OnProgress := Status;
        ZStream.CopyFrom(InFile, 0);
      finally
        ZStream.Free;
      end;
 
    finally
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end;
 
 
procedure TTest.Expand;
var
  Count: Integer;
begin
  InFile := TFileStream.Create('test.dat', fmOpenRead);
  try
 
    OutFile := TFileStream.Create('test.new', fmCreate);
    try
 
      ZStream := TDecompressionStream.Create(InFile);
      try
        TDecompressionStream(ZStream).OnProgress := Status;
        while True do
          begin
            Count := ZStream.Read(Buffer, BufferSize);
            if Count <> 0 then OutFile.WriteBuffer(Buffer, Count) else Break;
          end;
      finally
        ZStream.Free;
      end;
 
    finally
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end;
 
procedure TTest.Status(Sender: TObject);
begin
  Writeln(TCustomZLibStream(Sender).Position);
end;
 
var
  T: TTest;
begin
  T := TTest.Create;
  try
    T.Shrink;
    T.Expand;
  finally
    T.Free;
  end;
  Readln;
end.
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2598458
or
an example of saving C:\the.bmp as C:\new.dat then loading C:\new.dat into a TImage
  (note it dont use tcompressionstream for this just thought you may be interested):


implementation
 
uses
  ZLib;
 
....
 
procedure TForm1.Button1Click(Sender:
TObject);
var
  Strm: TMemoryStream;
  PStrm: Pointer;
  i: Integer;
begin
  Strm := TMemoryStream.Create;
  Strm.LoadFromFile('c:\the.bmp');
  Screen.Cursor := crHourGlass;
  CompressBuf(Strm.Memory, Strm.Size,
PStrm, i);
  Screen.Cursor := crDefault;
  Strm.Clear;
  Strm.Write(PStrm^, i);
  Strm.SaveToFile('c:\new.dat');
  Strm.Clear;
  Strm.Destroy;
end;
 
procedure TForm1.Button2Click(Sender:
TObject);
var
  Strm: TMemoryStream;
  PStrm: Pointer;
  tmp, i: Integer;
begin
  Strm := TMemoryStream.Create;
  Strm.LoadFromFile('c:\new.dat');
  Screen.Cursor := crHourGlass;
  DecompressBuf(Strm.Memory, Strm.Size,
tmp, PStrm, i);
  Screen.Cursor := crDefault;
  Strm.Clear;
  Strm.Write(PStrm^, i);
  Strm.Position := 0;
 
Image1.Picture.BitMap.LoadFromStream(Strm);
end;


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
URL for downloading Google Chrome for Win XP 2 232
update joined tables 2 62
Tidtcpserver listening on multiports? 1 42
migrate this code to work on android 1 27
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question