Solved

ZLIB TCompressionstream

Posted on 2000-03-08
2
1,051 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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