AddFromStream(Stream: IIOStream; ArchPath: String): IZipArchiveEntry;
AddFromStream(Stream: Prognoz.Platform.Interop.ForeIO.IIOStream; ArchPath: String): Prognoz.Platform.Interop.ForeIO.IZipArchiveEntry;
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.
The AddFromStream method adds a file to the archive passed in the specified stream.
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. On working in Fore.NET, add links to the ForeIO, ForeSystem assemblies.
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;
Imports Prognoz.Platform.Interop.ForeIO;
Imports Prognoz.Platform.Interop.ForeSystem;
Public Shared Sub Main(Params: StartParams);
Var
ZIP: IZipArchive = New ZipArchiveClass();
MStream: IMemoryStream = New MemoryStreamClass();
TxtWriter: ITextWriter = New TextWriterClass();
Begin
ZIP.Create("D:\Work\Archives\Data_Stream.zip", ZipMode.zmCreate, ZipCompressionLevel.zcDefaultCompression);
MStream.Create();
TxtWriter.Create(MStream);
TxtWriter.Encoding := CodePage.cpUTF8;
TxtWriter.WriteLnString("***File Info***");
TxtWriter.WriteString("Created: "); TxtWriter.WriteDateTime(DateTime.Now);
TxtWriter.Flush();
MStream.Position := 0;
ZIP.AddFromStream(MStream, "Info.txt");
System.Runtime.InteropServices.Marshal.ReleaseComObject(ZIP);
End Sub;
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: