Recent

Author Topic: How to unzip to a memory or to Stream-Memory?  (Read 259 times)

d2010

  • Full Member
  • ***
  • Posts: 161
How to unzip to a memory or to Stream-Memory?
« on: April 29, 2025, 07:49:39 am »
Hello..
First. I get size-uncompressed  for 01 files
Second. I alloc memory inside colander.lpi.exe
Third. I unzip to inside my memory internal?
My problem ::)
C:Q2=After, can you update at (???) ..
Please you toggle  between cozipinc_un/maketozip.
If you cannot unzip many files, then please how to unzip only once 01file-to-mem
enought.
 :-X
Code: Pascal  [Select][+][-]
  1. Function cozipinc_maketozip(AZipFilename, ADirectory, AMask: String;IncludingSubDirs: char): eurochar;
  2. var
  3.   OurZipper: TZipper;
  4.   list: TStringList;
  5.   ida: Integer;
  6.   diskFileName, archiveFileName: String;
  7. begin
  8.   assert_adu(354,'0');
  9.   result:='eeee';
  10.   ADirectory := IncludeTrailingPathDelimiter(ADirectory);
  11.   if DirectoryExists(ADirectory) then
  12.   begin
  13.      OurZipper := TZipper.Create;
  14.      try
  15.        // Set the name of the zip file to be created
  16.        OurZipper.FileName := AZipFileName;
  17.  
  18.        // Read names of the files contained in ADirectory to a stringlist
  19.        list := TStringList.Create;
  20.        try
  21.          // FindAllFiles adds all file names matching the mask (e.g. '*.*')
  22.          // found in the given directory to the provided list.
  23.          // When IncludingSubDirs is true the search continues recursively in
  24.          // the subdirectories.
  25.          FindAllFiles(list, ADirectory, AMask, IncludingSubDirs in ['A'..'Z']);
  26.          for ida := 0 to list.Count - 1 do
  27.          begin
  28.            // diskfilename is the name of the file to be zipped on the disk
  29.            diskFileName := list[ida];
  30.            // archivefilename is the name of the file to be zipped as it appears
  31.            // in the zip. We remove the deirectory from the
  32.            archiveFileName := StringReplace(diskFileName, ADirectory, '', []);
  33.            // Store these filenames for the zipper
  34.            OurZipper.Entries.AddFileEntry(diskFileName, archiveFileName);
  35.          end;
  36.        finally
  37.          list.Free;
  38.        end;
  39.        // By default zipper writes file names in encoding of the IBM PC, CP437.
  40.        // UTF8 encoding is written when UseLanguageEncoding is true.
  41.        OurZipper.UseLanguageEncoding := true;  // Requires FPC 3.2+
  42.        // create and write the zip file
  43.        Case IncludingSubDirs of
  44. 'D':   OurZipper.ZipAllFiles;
  45. 'd':   OurZipper.SaveToFile(AZipFilename);
  46. 'm':   OurZipper.SaveToStream(???)
  47.        End;
  48.        Result := 'oZip!t354okai good';
  49.      finally
  50.        OurZipper.Free;
  51.      end;
  52.   end else
  53.     Result := 'eZip!t354errorF..eDirectory Not Exists->You try other directory';
  54. end;
  55.  
Thank you.
« Last Edit: April 29, 2025, 10:01:10 pm by d2010 »

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: How to unzip to a memory or to Stream-Memory?
« Reply #1 on: April 29, 2025, 08:28:21 am »
C:Q2=After, can you update at (???) ..

Code: Pascal  [Select][+][-]
  1. // create memory stream (or any other stream-type)
  2. Stream := TMemoryStream.Create; //
  3.  
  4. // save ourzipper content to Stream
  5. OurZipper.SaveToStream(Stream);
  6.  
  7. // do something useful with Stream
  8.  
  9. // Release Stream
  10. Stream.Free;
  11.  



You keep changing the original post...

Quote
If you cannot unzip many files, then please how to unzip only once 01file-to-mem, ...
To unzip use something like the TUnzipper class instead. TZipper is only capable of creating archives.
« Last Edit: April 29, 2025, 10:01:00 pm by TRon »
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018