Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Updating existing zip files using SharpZipLib

$
0
0

Hi,

Currently I'm trying to update an existing zip file by adding file into it using the sample codes provided below:

using ICSharpCode.SharpZipLib.Zip;

public void UpdateExistingZip() {
    ZipFile zipFile = new ZipFile(@"c:\temp\existing.zip");

    // Must call BeginUpdate to start, and CommitUpdate at the end.
    zipFile.BeginUpdate();

    zipFile.Password = "whatever"; // Only if a password is wanted on the new entry

    // The "Add()" method will add or overwrite as necessary.
    // When the optional entryName parameter is omitted, the entry will be named
    // with the full folder path and without the drive e.g. "temp/folder/test1.txt".
    //
    zipFile.Add(@"c:\temp\folder\test1.txt");

    // Specify the entryName parameter to modify the name as it appears in the zip.
    //
    zipFile.Add(@"c:\temp\folder\test2.txt", "test2.txt");

    // Continue calling .Add until finished.

    // Both CommitUpdate and Close must be called.
    zipFile.CommitUpdate();
    zipFile.Close();
}

Reference: https://github.com/icsharpcode/SharpZipLib/wiki/Updating (Basic updating of a zip file)

 

With this, I faced three issues:

1) How can I set the DataTime of the file I'm going to add into an existing zip file?

In the zip samples (https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples) on the compressing of folder, it uses ZipEntry:

ZipEntry newEntry = new ZipEntry(entryName);
newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity

However, when I using the updating sample codes, I can't set the DateTime of the file I'm going to add into the archive. The file's DataTime I added recently in the archive follows the time I updated, and not the file original LastWriteTime.

 

2) How can I retrieve the CompressedSize of the file I'm going to add into an existing zip file?

The way I do it on the CompressFolder is to use the ZipEntry a retrieve it: long compressFileSize = newEntry.CompressedSize;

However, when I used the updating sample codes, I can't retrieve the CompressedSize of the compressed file I recently added into the archive.

 

3) How can I add file with unicode filename into an existing zip file?

The way I do it on the CompressFolder is to us the ZipEntry to set it: newEntry.IsUnicodeText = true;

However, when I used the updating sample codes, I can't set to allow unicode to be added into the archive.

 

Please Help!

 

Many Thanks! :)

 

Best Regards,

MrMaMaLuLu


Viewing all articles
Browse latest Browse all 1764

Trending Articles