C# Class NBug.Core.Util.Storage.ZipStorer

Unique class for compression/decompression file. Represents a Zip file.
Inheritance: IDisposable
Show file Open project: soygul/NBug Class Usage Examples

Public Properties

Property Type Description
EncodeUTF8 bool
ForceDeflating bool

Public Methods

Method Description
AddFile ( Compression _method, string _pathname, string _filenameInZip, string _comment, FileShare _share = FileShare.Read ) : void

Add full contents of a file into the Zip storage

AddStream ( Compression _method, string _filenameInZip, Stream _source, System.DateTime _modTime, string _comment ) : void

Add full contents of a stream into the Zip storage

Close ( ) : void

Updates central directory (if pertinent) and close the Zip storage

This is a required step, unless automatic dispose is used

Create ( Stream _stream, string _comment ) : ZipStorer

Method to create a new zip storage in a stream

Create ( string _filename, string _comment ) : ZipStorer

Method to create a new storage file

Dispose ( ) : void

Closes the Zip file stream

ExtractFile ( ZipFileEntry _zfe, Stream _stream ) : bool

Copy the contents of a stored file into an opened stream

Unique compression methods are Store and Deflate

ExtractFile ( ZipFileEntry _zfe, string _filename ) : bool

Copy the contents of a stored file into a physical file

Unique compression methods are Store and Deflate

Open ( Stream _stream, FileAccess _access ) : ZipStorer

Method to open an existing storage from stream

Open ( string _filename, FileAccess _access ) : ZipStorer

Method to open an existing storage file

ReadCentralDir ( ) : List

Read all the file records in the central directory

RemoveEntries ( ZipStorer &_zip, List _zfes ) : bool

Removes one of many files in storage. It creates a new Zip file.

This method only works for storage of type FileStream

Private Methods

Method Description
DateTimeToDosTime ( System.DateTime _dt ) : uint

The date time to dos time.

DosTimeToDateTime ( uint _dt ) : System.DateTime

The dos time to date time.

GetFileOffset ( uint _headerOffset ) : uint

The get file offset.

NormalizedFilename ( string _filename ) : string

The normalized filename.

ReadFileInfo ( ) : bool

The read file info.

Store ( ZipFileEntry &_zfe, Stream _source ) : void

The store.

UpdateCrcAndSizes ( ZipFileEntry &_zfe ) : void

The update crc and sizes.

WriteCentralDirRecord ( ZipFileEntry _zfe ) : void

The write central dir record.

WriteEndRecord ( uint _size, uint _offset ) : void

The write end record.

WriteLocalHeader ( ZipFileEntry &_zfe ) : void

The write local header.

ZipStorer ( ) : System

Initializes static members of the ZipStorer class.

Method Details

AddFile() public method

Add full contents of a file into the Zip storage
public AddFile ( Compression _method, string _pathname, string _filenameInZip, string _comment, FileShare _share = FileShare.Read ) : void
_method Compression /// Compression method ///
_pathname string /// Full path of file to add to Zip storage ///
_filenameInZip string /// Filename and path as desired in Zip directory ///
_comment string /// Comment for stored file ///
_share FileShare
return void

AddStream() public method

Add full contents of a stream into the Zip storage
public AddStream ( Compression _method, string _filenameInZip, Stream _source, System.DateTime _modTime, string _comment ) : void
_method Compression /// Compression method ///
_filenameInZip string /// Filename and path as desired in Zip directory ///
_source Stream /// Stream object containing the data to store in Zip ///
_modTime System.DateTime /// Modification time of the data to store ///
_comment string /// Comment for stored file ///
return void

Close() public method

Updates central directory (if pertinent) and close the Zip storage
This is a required step, unless automatic dispose is used
public Close ( ) : void
return void

Create() public static method

Method to create a new zip storage in a stream
public static Create ( Stream _stream, string _comment ) : ZipStorer
_stream Stream ///
_comment string ///
return ZipStorer

Create() public static method

Method to create a new storage file
public static Create ( string _filename, string _comment ) : ZipStorer
_filename string /// Full path of Zip file to create ///
_comment string /// General comment for Zip file ///
return ZipStorer

Dispose() public method

Closes the Zip file stream
public Dispose ( ) : void
return void

ExtractFile() public method

Copy the contents of a stored file into an opened stream
Unique compression methods are Store and Deflate
public ExtractFile ( ZipFileEntry _zfe, Stream _stream ) : bool
_zfe ZipFileEntry /// Entry information of file to extract ///
_stream Stream /// Stream to store the uncompressed data ///
return bool

ExtractFile() public method

Copy the contents of a stored file into a physical file
Unique compression methods are Store and Deflate
public ExtractFile ( ZipFileEntry _zfe, string _filename ) : bool
_zfe ZipFileEntry /// Entry information of file to extract ///
_filename string /// Name of file to store uncompressed data ///
return bool

Open() public static method

Method to open an existing storage from stream
public static Open ( Stream _stream, FileAccess _access ) : ZipStorer
_stream Stream /// Already opened stream with zip contents ///
_access FileAccess /// File access mode for stream operations ///
return ZipStorer

Open() public static method

Method to open an existing storage file
public static Open ( string _filename, FileAccess _access ) : ZipStorer
_filename string /// Full path of Zip file to open ///
_access FileAccess /// File access mode as used in FileStream constructor ///
return ZipStorer

ReadCentralDir() public method

Read all the file records in the central directory
public ReadCentralDir ( ) : List
return List

RemoveEntries() public static method

Removes one of many files in storage. It creates a new Zip file.
This method only works for storage of type FileStream
public static RemoveEntries ( ZipStorer &_zip, List _zfes ) : bool
_zip ZipStorer /// Reference to the current Zip object ///
_zfes List /// List of Entries to remove from storage ///
return bool

Property Details

EncodeUTF8 public property

True if UTF8 encoding for filename and comments, false if default (CP 437)
public bool EncodeUTF8
return bool

ForceDeflating public property

Force deflate algotithm even if it inflates the stored file. Off by default.
public bool ForceDeflating
return bool