IZipArchive.AddFromStream

Syntax

AddFromStream(Stream: IIOStream; ArchPath: String): IZipArchiveEntry;

Parameters

Stream. Stream connected with the file that must be added to archive.

ArchPath. Path to the archive folder and name of the file, with which the file is added from the stream.

Description

The AddFromStream method adds a file to the archive passed in the specified stream.

Example

Executing the example requires the D:\Work folder on the hard drive, the folder contains the Archives subfolder to store archive files.

Add a link to the IO system assembly.

Sub UserProc;
Var
    ZIP: IZipArchive;
    MStream: IMemoryStream;
    TxtWriter: ITextWriter;
Begin
    ZIP := New ZipArchive.Create("d:\Work\Archives\Data_Stream.zip", ZipMode.Create);
    MStream := New MemoryStream.Create;
    TxtWriter := New TextWriter.Create(MStream);
    TxtWriter.Encoding := CodePage.UTF8;
    TxtWriter.WriteLnString("***File Info***");
    TxtWriter.WriteString("Created: "); TxtWriter.WriteDateTime(DateTime.Now);
    TxtWriter.Flush;
    MStream.Position := 0;
    ZIP.AddFromStream(MStream, "Info.txt");
    Dispose ZIP;
End Sub UserProc;

After executing the example the Data_Stream.zip archive is created. The file that was created in the memory during example execution is added to the archive.

See also:

IZipArchive