ZipArchiveMode ZipArchiveMode ZipArchiveMode ZipArchiveMode Enum

定义

指定与 zip 存档项互交的值。Specifies values for interacting with zip archive entries.

public enum class ZipArchiveMode
public enum ZipArchiveMode
type ZipArchiveMode = 
Public Enum ZipArchiveMode
继承
ZipArchiveModeZipArchiveModeZipArchiveModeZipArchiveMode

字段

Create Create Create Create 1

只允许创建新的存档项。Only creating new archive entries is permitted.

Read Read Read Read 0

只允许读取存档项。Only reading archive entries is permitted.

Update Update Update Update 2

允许对存档项执行读取和写入操作。Both read and write operations are permitted for archive entries.

示例

下面的示例演示如何指定ZipArchiveMode值时创建ZipArchive.ZipArchive(Stream, ZipArchiveMode)对象。The following example shows how to specify a ZipArchiveMode value when creating a ZipArchive.ZipArchive(Stream, ZipArchiveMode) object.

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\release.zip", FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt");
                    using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
                    {
                            writer.WriteLine("Information about this package.");
                            writer.WriteLine("========================");
                    }
                }
            }
        }
    }
}
Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Using zipToOpen As FileStream = New FileStream("c:\users\exampleuser\release.zip", FileMode.Open)
            Using archive As ZipArchive = New ZipArchive(zipToOpen, ZipArchiveMode.Update)
                Dim readmeEntry As ZipArchiveEntry = archive.CreateEntry("Readme.txt")
                Using writer As StreamWriter = New StreamWriter(readmeEntry.Open())
                    writer.WriteLine("Information about this package.")
                    writer.WriteLine("========================")
                End Using
            End Using
        End Using
    End Sub

End Module

注解

当将模式设置为读取时,基础文件或流必须支持读取,但不需要支持查找。When you set the mode to Read, the underlying file or stream must support reading, but does not have to support seeking. 如果基础文件或流支持查找,则根据请求从存档读取文件。If the underlying file or stream supports seeking, the files are read from the archive as they are requested. 如果基础文件或流不支持查找,则将整个存档保存在内存中。If the underlying file or stream does not support seeking, the entire archive is held in memory.

当将模式设置为创建时,基础文件或流必须支持写入,但不需要支持查找。When you set the mode to Create, the underlying file or stream must support writing, but does not have to support seeking. 存档中的每个项可以一次只能打开进行写入。Each entry in the archive can be opened only once for writing. 如果创建单个条目,将数据写入基础流或文件立即可用。If you create a single entry, the data is written to the underlying stream or file as soon as it is available. 如果创建多个项,例如通过调用CreateFromDirectory方法中,将数据写入基础流或文件后创建的所有条目。If you create multiple entries, such as by calling the CreateFromDirectory method, the data is written to the underlying stream or file after all the entries are created.

当将模式设置为更新后时,读取、 写入和查找必须支持的基础的文件或流。When you set the mode to Update, the underlying file or stream must support reading, writing, and seeking. 整个存档的内容保留在内存中,直到释放的存档到基础文件或流中写入数据。The content of the entire archive is held in memory, and no data is written to the underlying file or stream until the archive is disposed.

以下方法包括一个名为参数mode它允许您指定的存档模式:The following methods include a parameter named mode that lets you specify the archive mode:

适用于