C# Класс System.IO.Compression.ZipFileExtensions

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
CreateEntryFromFile ( this destination, string sourceFileName, string entryName ) : ZipArchiveEntry

Adds a file from the file system to the archive under the specified entry name. The new entry in the archive will contain the contents of the file. The last write time of the archive entry is set to the last write time of the file on the file system. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name. If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.

Since no CompressionLevel is specified, the default provided by the implementation of the underlying compression algorithm will be used; the ZipArchive will not impose its own default. (Currently, the underlying compression algorithm is provided by the System.IO.Compression.DeflateStream class.)

CreateEntryFromFile ( this destination, string sourceFileName, string entryName, CompressionLevel compressionLevel ) : ZipArchiveEntry

Adds a file from the file system to the archive under the specified entry name. The new entry in the archive will contain the contents of the file. The last write time of the archive entry is set to the last write time of the file on the file system. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name. If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.

ExtractToDirectory ( this source, string destinationDirectoryName ) : void

Extracts all of the files in the archive to a directory on the file system. The specified directory may already exist. This method will create all subdirectories and the specified directory if necessary. If there is an error while extracting the archive, the archive will remain partially extracted. Each entry will be extracted such that the extracted file has the same relative path to destinationDirectoryName as the entry has to the root of the archive. If a file to be archived has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

ExtractToFile ( this source, string destinationFileName ) : void

Creates a file on the file system with the entry?s contents and the specified name. The last write time of the file is set to the entry?s last write time. This method does not allow overwriting of an existing file with the same name. Attempting to extract explicit directories (entries with names that end in directory separator characters) will not result in the creation of a directory.

ExtractToFile ( this source, string destinationFileName, bool overwrite ) : void

Creates a file on the file system with the entry?s contents and the specified name. The last write time of the file is set to the entry?s last write time. This method does allows overwriting of an existing file with the same name.

Приватные методы

Метод Описание
DoCreateEntryFromFile ( ZipArchive destination, string sourceFileName, string entryName, CompressionLevel compressionLevel ) : ZipArchiveEntry

Описание методов

CreateEntryFromFile() публичный статический Метод

Adds a file from the file system to the archive under the specified entry name. The new entry in the archive will contain the contents of the file. The last write time of the archive entry is set to the last write time of the file on the file system. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name. If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.

Since no CompressionLevel is specified, the default provided by the implementation of the underlying compression algorithm will be used; the ZipArchive will not impose its own default. (Currently, the underlying compression algorithm is provided by the System.IO.Compression.DeflateStream class.)

sourceFileName is a zero-length string, contains only white space, or contains one or more /// invalid characters as defined by InvalidPathChars. -or- entryName is a zero-length string. sourceFileName or entryName is null. In sourceFileName, the specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The specified sourceFileName is invalid, (for example, it is on an unmapped drive). An I/O error occurred while opening the file specified by sourceFileName. sourceFileName specified a directory. -or- The caller does not have the /// required permission. The file specified in sourceFileName was not found. sourceFileName is in an invalid format or the ZipArchive does not support writing. The ZipArchive has already been closed.
public static CreateEntryFromFile ( this destination, string sourceFileName, string entryName ) : ZipArchiveEntry
destination this
sourceFileName string The path to the file on the file system to be copied from. The path is permitted to specify /// relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
entryName string The name of the entry to be created.
Результат ZipArchiveEntry

CreateEntryFromFile() публичный статический Метод

Adds a file from the file system to the archive under the specified entry name. The new entry in the archive will contain the contents of the file. The last write time of the archive entry is set to the last write time of the file on the file system. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name. If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.

If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.

sourceFileName is a zero-length string, contains only white space, or contains one or more /// invalid characters as defined by InvalidPathChars. -or- entryName is a zero-length string. sourceFileName or entryName is null. In sourceFileName, the specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The specified sourceFileName is invalid, (for example, it is on an unmapped drive). An I/O error occurred while opening the file specified by sourceFileName. sourceFileName specified a directory. /// -or- The caller does not have the required permission. The file specified in sourceFileName was not found. sourceFileName is in an invalid format or the ZipArchive does not support writing. The ZipArchive has already been closed.
public static CreateEntryFromFile ( this destination, string sourceFileName, string entryName, CompressionLevel compressionLevel ) : ZipArchiveEntry
destination this
sourceFileName string The path to the file on the file system to be copied from. The path is permitted to specify relative /// or absolute path information. Relative path information is interpreted as relative to the current working directory.
entryName string The name of the entry to be created.
compressionLevel CompressionLevel The level of the compression (speed/memory vs. compressed size trade-off).
Результат ZipArchiveEntry

ExtractToDirectory() публичный статический Метод

Extracts all of the files in the archive to a directory on the file system. The specified directory may already exist. This method will create all subdirectories and the specified directory if necessary. If there is an error while extracting the archive, the archive will remain partially extracted. Each entry will be extracted such that the extracted file has the same relative path to destinationDirectoryName as the entry has to the root of the archive. If a file to be archived has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used.
destinationDirectoryName is a zero-length string, contains only white space, /// or contains one or more invalid characters as defined by InvalidPathChars. destinationDirectoryName is null. The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The specified path is invalid, (for example, it is on an unmapped drive). An archive entry?s name is zero-length, contains only white space, or contains one or more invalid /// characters as defined by InvalidPathChars. -or- Extracting an archive entry would have resulted in a destination /// file that is outside destinationDirectoryName (for example, if the entry name contains parent directory accessors). /// -or- An archive entry has the same name as an already extracted entry from the same archive. The caller does not have the required permission. destinationDirectoryName is in an invalid format. An archive entry was not found or was corrupt. /// -or- An archive entry has been compressed using a compression method that is not supported.
public static ExtractToDirectory ( this source, string destinationDirectoryName ) : void
source this
destinationDirectoryName string The path to the directory on the file system. /// The directory specified must not exist. The path is permitted to specify relative or absolute path information. /// Relative path information is interpreted as relative to the current working directory.
Результат void

ExtractToFile() публичный статический Метод

Creates a file on the file system with the entry?s contents and the specified name. The last write time of the file is set to the entry?s last write time. This method does not allow overwriting of an existing file with the same name. Attempting to extract explicit directories (entries with names that end in directory separator characters) will not result in the creation of a directory.
The caller does not have the required permission. destinationFileName is a zero-length string, contains only white space, or contains one or more /// invalid characters as defined by InvalidPathChars. -or- destinationFileName specifies a directory. destinationFileName is null. The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The path specified in destinationFileName is invalid (for example, it is on /// an unmapped drive). destinationFileName already exists. /// -or- An I/O error has occurred. -or- The entry is currently open for writing. /// -or- The entry has been deleted from the archive. destinationFileName is in an invalid format /// -or- The ZipArchive that this entry belongs to was opened in a write-only mode. The entry is missing from the archive or is corrupt and cannot be read /// -or- The entry has been compressed using a compression method that is not supported. The ZipArchive that this entry belongs to has been disposed.
public static ExtractToFile ( this source, string destinationFileName ) : void
source this
destinationFileName string The name of the file that will hold the contents of the entry. /// The path is permitted to specify relative or absolute path information. /// Relative path information is interpreted as relative to the current working directory.
Результат void

ExtractToFile() публичный статический Метод

Creates a file on the file system with the entry?s contents and the specified name. The last write time of the file is set to the entry?s last write time. This method does allows overwriting of an existing file with the same name.
The caller does not have the required permission. destinationFileName is a zero-length string, contains only white space, /// or contains one or more invalid characters as defined by InvalidPathChars. -or- destinationFileName specifies a directory. destinationFileName is null. The specified path, file name, or both exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. The path specified in destinationFileName is invalid /// (for example, it is on an unmapped drive). destinationFileName exists and overwrite is false. /// -or- An I/O error has occurred. /// -or- The entry is currently open for writing. /// -or- The entry has been deleted from the archive. destinationFileName is in an invalid format /// -or- The ZipArchive that this entry belongs to was opened in a write-only mode. The entry is missing from the archive or is corrupt and cannot be read /// -or- The entry has been compressed using a compression method that is not supported. The ZipArchive that this entry belongs to has been disposed.
public static ExtractToFile ( this source, string destinationFileName, bool overwrite ) : void
source this
destinationFileName string The name of the file that will hold the contents of the entry. /// The path is permitted to specify relative or absolute path information. /// Relative path information is interpreted as relative to the current working directory.
overwrite bool True to indicate overwrite.
Результат void