MemoryStream ms1 = new MemoryStream();
using (ZipArchive archive = new ZipArchive(ms1, ZipArchiveMode.Create, false, null))
{
using (PdfFileSource fileSource = new PdfFileSource(File.OpenRead(documentToSplit)))
{
string splitDocumentName = "1st page.pdf";
using (ZipArchiveEntry entry = archive.CreateEntry(splitDocumentName))
{
using (PdfStreamWriter writer = new PdfStreamWriter(entry.Open()))
{
PdfPageSource page = fileSource.Pages[0];
writer.WritePage(page);
}
}
}
}
File.WriteAllBytes("exported.zip", ms1.ToArray());
Currently, an exception is thrown when the file being unzipped already exists in the destination folder. Expose overload of the ExtractToDirectory() method allowing users to overwrite files.
Alternatively, the ZipArchiveEntry.ExtractToFile() method can be used:
using (ZipArchive source = ZipFile.Open(sourceFileName, ZipArchiveMode.Read, null))
{
foreach (ZipArchiveEntry entry in source.Entries)
{
string fullPath = Path.GetFullPath(Path.Combine(destinationDirectory, entry.FullName));
if (Path.GetFileName(fullPath).Length != 0)
{
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
// The boolean parameter determines whether an existing file that has the same name as the destination file should be overwritten
entry.ExtractToFile(fullPath, true);
}
}
}
Add support for AES Encryption.
Provide a simple method to detect that a password for a ZIP file is not valid.
The current implemention usually throws an exception (which does not definitively identify the password as wrong), but not always. Sometimes it just returns corrupt data.
It would be nice to either have a typed exception consistently thrown, or a method to specifically check for an invalid password.
Thanks.
7zip and the Windows arvhiver report Data Error on all the files when the users try to extract an archive created with ZipLibrary and the default LzmaSettings.
Provide a way for users to check whether a stream is a valid zip archive. Include a CRC check as well.
According to the specification, the Enhanced Deflating algorithm is similar to Deflate but uses a sliding dictionary of up to 64K.
When updating ZIP archive, there is no need for loading it fully in the memory. Each entry is represented as a separate stream; when the ZipArchive is disposed, each entry is written in the OutputStream which is MemoryStream. When an entry is written in the OutputStream it is read from the source file if it is not changed. The MemoryStream is used because the source file is needed to get the entries contents. A temporary file can be used instead and there will be no need of the memory stream, so that large files will be updated without using much memory (which causes OutOfMemoryException).
There should be API allowing to check if an archive is protected.
Add functionality for the ZipPackage to span across multiple files.