Class FastZip
FastZip provides facilities for creating and extracting zip files.
Inheritance
Inherited Members
Namespace: ICSharpCode.SharpZipLib.Zip
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class FastZip
Constructors
| Improve this Doc View SourceFastZip()
Initialise a default instance of FastZip.
Declaration
public FastZip()
FastZip(FastZipEvents)
Initialise a new instance of FastZip
Declaration
public FastZip(FastZipEvents events)
Parameters
Type | Name | Description |
---|---|---|
FastZipEvents | events | The events to use during operations. |
FastZip(ZipEntryFactory.TimeSetting)
Initialise a new instance of FastZip using the specified ZipEntryFactory.TimeSetting
Declaration
public FastZip(ZipEntryFactory.TimeSetting timeSetting)
Parameters
Type | Name | Description |
---|---|---|
ZipEntryFactory.TimeSetting | timeSetting | The time setting to use when creating or extracting Zip entries. |
Remarks
Using TimeSetting.LastAccessTime[Utc] when creating an archive will set the file time to the moment of reading.
FastZip(DateTime)
Initialise a new instance of FastZip using the specified System.DateTime
Declaration
public FastZip(DateTime time)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | time | The time to set all DateTime values for created or extracted Zip Entries. |
Properties
| Improve this Doc View SourceCompressionLevel
Get/set the Compression Level that will be used when creating the zip
Declaration
public Deflater.CompressionLevel CompressionLevel { get; set; }
Property Value
Type | Description |
---|---|
Deflater.CompressionLevel |
CreateEmptyDirectories
Get/set a value indicating whether empty directories should be created.
Declaration
public bool CreateEmptyDirectories { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
EntryEncryptionMethod
Get / set the method of encrypting entries.
Declaration
public ZipEncryptionMethod EntryEncryptionMethod { get; set; }
Property Value
Type | Description |
---|---|
ZipEncryptionMethod |
Remarks
Only applies when Password is set. Defaults to ZipCrypto for backwards compatibility purposes.
EntryFactory
Get or set the IEntryFactory active when creating Zip files.
Declaration
public IEntryFactory EntryFactory { get; set; }
Property Value
Type | Description |
---|---|
IEntryFactory |
LegacyCodePage
Gets or sets the code page used for reading/writing zip file entries when unicode is disabled
Declaration
public int LegacyCodePage { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
NameTransform
Get or set the INameTransform active when creating Zip files.
Declaration
public INameTransform NameTransform { get; set; }
Property Value
Type | Description |
---|---|
INameTransform |
See Also
| Improve this Doc View SourcePassword
Get / set the password value.
Declaration
public string Password { get; set; }
Property Value
Type | Description |
---|---|
System.String |
RestoreAttributesOnExtract
Get/set a value indicating whether file attributes should be restored during extract operations
Declaration
public bool RestoreAttributesOnExtract { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
RestoreDateTimeOnExtract
Get/set a value indicating whether file dates and times should be restored when extracting files from an archive.
Declaration
public bool RestoreDateTimeOnExtract { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
The default value is false.
StringCodec
Utility class for resolving the encoding used for reading and writing strings
Declaration
public StringCodec StringCodec { get; set; }
Property Value
Type | Description |
---|---|
StringCodec |
UseUnicode
Reflects the opposite of the internal ForceZipLegacyEncoding, setting it to false
overrides the encoding used for reading and writing zip entries
Declaration
public bool UseUnicode { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
UseZip64
Gets or sets the setting for Zip64 handling when writing.
Declaration
public UseZip64 UseZip64 { get; set; }
Property Value
Type | Description |
---|---|
UseZip64 |
Remarks
The default value is dynamic which is not backwards compatible with old programs and can cause problems with XP's built in compression which cant read Zip64 archives. However it does avoid the situation were a large file is added and cannot be completed correctly. NOTE: Setting the size for entries before they are added is the best solution! By default the EntryFactory used by FastZip will set the file size.
Methods
| Improve this Doc View SourceCreateZip(Stream, String, Boolean, IScanFilter, IScanFilter, Boolean)
Create a zip archive sending output to the outputStream
passed.
Declaration
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, IScanFilter fileFilter, IScanFilter directoryFilter, bool leaveOpen = false)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | The stream to write archive data to. |
System.String | sourceDirectory | The directory to source files from. |
System.Boolean | recurse | True to recurse directories, false for no recursion. |
IScanFilter | fileFilter | The file filter to apply. |
IScanFilter | directoryFilter | The directory filter to apply. |
System.Boolean | leaveOpen | true to leave |
CreateZip(Stream, String, Boolean, String, String)
Create a zip archive sending output to the outputStream
passed.
Declaration
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | The stream to write archive data to. |
System.String | sourceDirectory | The directory to source files from. |
System.Boolean | recurse | True to recurse directories, false for no recursion. |
System.String | fileFilter | The file filter to apply. |
System.String | directoryFilter | The directory filter to apply. |
Remarks
The outputStream
is closed after creation.
CreateZip(Stream, String, Boolean, String, String, Boolean)
Create a zip archive sending output to the outputStream
passed.
Declaration
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter, bool leaveOpen)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | outputStream | The stream to write archive data to. |
System.String | sourceDirectory | The directory to source files from. |
System.Boolean | recurse | True to recurse directories, false for no recursion. |
System.String | fileFilter | The file filter to apply. |
System.String | directoryFilter | The directory filter to apply. |
System.Boolean | leaveOpen | true to leave |
CreateZip(String, String, Boolean, IScanFilter, IScanFilter)
Create a zip file.
Declaration
public void CreateZip(string zipFileName, string sourceDirectory, bool recurse, IScanFilter fileFilter, IScanFilter directoryFilter)
Parameters
Type | Name | Description |
---|---|---|
System.String | zipFileName | The name of the zip file to create. |
System.String | sourceDirectory | The directory to source files from. |
System.Boolean | recurse | True to recurse directories, false for no recursion. |
IScanFilter | fileFilter | The file filter to apply. |
IScanFilter | directoryFilter | The directory filter to apply. |
CreateZip(String, String, Boolean, String)
Create a zip file/archive.
Declaration
public void CreateZip(string zipFileName, string sourceDirectory, bool recurse, string fileFilter)
Parameters
Type | Name | Description |
---|---|---|
System.String | zipFileName | The name of the zip file to create. |
System.String | sourceDirectory | The directory to obtain files and directories from. |
System.Boolean | recurse | True to recurse directories, false for no recursion. |
System.String | fileFilter | The file filter to apply. |
CreateZip(String, String, Boolean, String, String)
Create a zip file.
Declaration
public void CreateZip(string zipFileName, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
Parameters
Type | Name | Description |
---|---|---|
System.String | zipFileName | The name of the zip file to create. |
System.String | sourceDirectory | The directory to source files from. |
System.Boolean | recurse | True to recurse directories, false for no recursion. |
System.String | fileFilter | The file filter to apply. |
System.String | directoryFilter | The directory filter to apply. |
ExtractZip(Stream, String, FastZip.Overwrite, FastZip.ConfirmOverwriteDelegate, String, String, Boolean, Boolean, Boolean)
Extract the contents of a zip file held in a stream.
Declaration
public void ExtractZip(Stream inputStream, string targetDirectory, FastZip.Overwrite overwrite, FastZip.ConfirmOverwriteDelegate confirmDelegate, string fileFilter, string directoryFilter, bool restoreDateTime, bool isStreamOwner, bool allowParentTraversal = false)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputStream | The seekable input stream containing the zip to extract from. |
System.String | targetDirectory | The directory to save extracted information in. |
FastZip.Overwrite | overwrite | The style of overwriting to apply. |
FastZip.ConfirmOverwriteDelegate | confirmDelegate | A delegate to invoke when confirming overwriting. |
System.String | fileFilter | A filter to apply to files. |
System.String | directoryFilter | A filter to apply to directories. |
System.Boolean | restoreDateTime | Flag indicating whether to restore the date and time for extracted files. |
System.Boolean | isStreamOwner | Flag indicating whether the inputStream will be closed by this method. |
System.Boolean | allowParentTraversal | Allow parent directory traversal in file paths (e.g. ../file) |
ExtractZip(String, String, FastZip.Overwrite, FastZip.ConfirmOverwriteDelegate, String, String, Boolean, Boolean)
Extract the contents of a zip file.
Declaration
public void ExtractZip(string zipFileName, string targetDirectory, FastZip.Overwrite overwrite, FastZip.ConfirmOverwriteDelegate confirmDelegate, string fileFilter, string directoryFilter, bool restoreDateTime, bool allowParentTraversal = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | zipFileName | The zip file to extract from. |
System.String | targetDirectory | The directory to save extracted information in. |
FastZip.Overwrite | overwrite | The style of overwriting to apply. |
FastZip.ConfirmOverwriteDelegate | confirmDelegate | A delegate to invoke when confirming overwriting. |
System.String | fileFilter | A filter to apply to files. |
System.String | directoryFilter | A filter to apply to directories. |
System.Boolean | restoreDateTime | Flag indicating whether to restore the date and time for extracted files. |
System.Boolean | allowParentTraversal | Allow parent directory traversal in file paths (e.g. ../file) |
ExtractZip(String, String, String)
Extract the contents of a zip file.
Declaration
public void ExtractZip(string zipFileName, string targetDirectory, string fileFilter)
Parameters
Type | Name | Description |
---|---|---|
System.String | zipFileName | The zip file to extract from. |
System.String | targetDirectory | The directory to save extracted information in. |
System.String | fileFilter | A filter to apply to files. |