Недавно добавленные исходники

•  TDictionary Custom Sort  3 224

•  Fast Watermark Sources  2 990

•  3D Designer  4 750

•  Sik Screen Capture  3 259

•  Patch Maker  3 467

•  Айболит (remote control)  3 527

•  ListBox Drag & Drop  2 903

•  Доска для игры Реверси  80 764

•  Графические эффекты  3 842

•  Рисование по маске  3 171

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 672

•  Рисование Луны  2 500

•  Поворот изображения  2 091

•  Рисование стержней  2 119

•  Paint on Shape  1 523

•  Генератор кроссвордов  2 182

•  Головоломка Paletto  1 730

•  Теорема Монжа об окружностях  2 158

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 016

•  Игра HIP  1 262

•  Игра Go (Го)  1 200

•  Симулятор лифта  1 421

•  Программа укладки плитки  1 177

•  Генератор лабиринта  1 512

•  Проверка числового ввода  1 297

•  HEX View  1 466

•  Физический маятник  1 322

•  Задача коммивояжера  1 357

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Сжимаем и разжимаем потоки




uses 
  ZLib; 

{ Compress a stream } 

procedure CompressStream(inpStream, outStream: TStream); 
var 
  InpBuf, OutBuf: Pointer; 
  InpBytes, OutBytes: Integer; 
begin 
  InpBuf := nil; 
  OutBuf := nil; 
  try 
    GetMem(InpBuf, inpStream.Size); 
    inpStream.Position := 0; 
    InpBytes := inpStream.Read(InpBuf^, inpStream.Size); 
    CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes); 
    outStream.Write(OutBuf^, OutBytes); 
  finally 
    if InpBuf <> nil then FreeMem(InpBuf); 
    if OutBuf <> nil then FreeMem(OutBuf); 
  end; 
end; 


{ Decompress a stream } 
procedure DecompressStream(inpStream, outStream: TStream); 
var 
  InpBuf, OutBuf: Pointer; 
  OutBytes, sz: Integer; 
begin 
  InpBuf := nil; 
  OutBuf := nil; 
  sz     := inpStream.Size - inpStream.Position; 
  if sz > 0 then  
    try 
      GetMem(InpBuf, sz); 
      inpStream.Read(InpBuf^, sz); 
      DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes); 
      outStream.Write(OutBuf^, OutBytes); 
    finally 
      if InpBuf <> nil then FreeMem(InpBuf); 
      if OutBuf <> nil then FreeMem(OutBuf); 
    end; 
  outStream.Position := 0; 
end; 


{ 
  Example: 
   Compress the contents of RichEdit1 and 
   calculate the compression rate. 
   Then save the stream to a file (ms2.dat) 

  Beispiel: 
   Komprimiert den Inhalt von RichEdit1 und 
   berechnet die Kompressionsrate. 
   Dann wird der Stream in eine Datei (ms2.dat) gespeichert. 
} 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  ms1, ms2: TMemoryStream; 
begin 
  ms1 := TMemoryStream.Create; 
  try 
    ms2 := TMemoryStream.Create; 
    try 
      RichEdit1.Lines.SaveToStream(ms1); 
      CompressStream(ms1, ms2); 
      ShowMessage(Format('Stream Compression Rate: %d %%', 
        [round(100 / ms1.Size * ms2.Size)])); 
      ms2.SaveToFile('C:\ms2.dat'); 
    finally 
      ms1.Free; 
    end; 
  finally 
    ms2.Free; 
  end; 
end; 

{ 
  Loads the stream from a file (ms2.dat) 
  and decompresses it. 
  Then loads the Stream to RichEdit1. 

  Ladt den komprimierten Stream von einer Datei (ms2.dat) 
  und dekomprimiert ihn. 
  Dann wird der Stream wieder in RichEdit1 geladen. 
} 

procedure TForm1.Button2Click(Sender: TObject); 
var 
  ms1, ms2: TMemoryStream; 
begin 
  ms1 := TMemoryStream.Create; 
  try 
    ms2 := TMemoryStream.Create; 
    try 
      ms1.LoadFromFile('C:\ms2.dat'); 
      DecompressStream(ms1, ms2); 
      RichEdit1.Lines.LoadFromStream(ms2); 
    finally 
      ms1.Free; 
    end; 
  finally 
    ms2.Free; 
  end; 
end;





Похожие по теме исходники

Потоки NTFS

Потоки Multi Thread




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте