In the new package v1.2.5309 which will be available for download next week resides a new feature you won't see much emphasis about, but which I was very eager to complete. You can now create a ZipArchive instance around an AbstractFile that does not support reading from.
(drum roll) ... (looking around) ... Nobody's applauding? That's because you probably don't know yet how useful this can be.
Most ASP.NET applications that wish to create zip files on the fly and send them in the response are either stuck with creating those zip files on disk in a temporary filename, or create them in a MemoryFile, then copy that MemoryFile in the response stream.
However, the StreamFile class was created for such purposes of exposing any existing Stream as an AbstractFile. You already could create a StreamFile around the Response's OutputStream. But passing that StreamFile to the ZipArchive's constructor would fail, because it can't read from it. Instead of assuming an empty zip file, it miserably failed. Shame.
No more... Since version 2.2.5302, it will assume the zip file is empty. So code like this works perfectly:
public void ProcessRequest(HttpContext context)
{ context.Response.ContentType = "application/zip";
context.Response.AddHeader( "Content-Disposition", "attachment; filename=images.bmp" );
ZipArchive archive = new ZipArchive( new StreamFile( context.Response.OutputStream ) );
DiskFolder source = new DiskFolder( context.Request.MapPath( "." ) );
source.CopyFilesTo( archive, false, false, "*.bmp" );
}
The same problem appeared when trying to combine Xceed Zip for .NET with Xceed FTP for .NET, to upload zip files directly on the FTP server. Though the FtpClient class exposes a very useful GetUploadStream method to get a direct stream on the data connection, code like this previously failed.
using( Stream upload = client.GetUploadStream( "images.zip" ) )
{ ZipArchive archive = new ZipArchive( new StreamFile( upload ) );
DiskFolder source = new DiskFolder( @"d:\images\" );
source.CopyFilesTo( archive, false, false, "*.bmp" );
}
Talk about short and sweet uploads of zip files!