Skip to content

Instantly share code, notes, and snippets.

@tomsseisums
Created March 31, 2015 14:53
Show Gist options
  • Save tomsseisums/16108aeb0c656be9ce48 to your computer and use it in GitHub Desktop.
Save tomsseisums/16108aeb0c656be9ce48 to your computer and use it in GitHub Desktop.
Zip as a stream in NancyFX
public class LogZipResponse : Response
{
public LogZipResponse ()
{
this.Contents = GetLogZip();
this.ContentType = "application/x-zip-compressed";
this.StatusCode = HttpStatusCode.OK;
}
private Action<Stream> GetLogZip()
{
return stream =>
{
using (ZipFile logZip = new ZipFile())
{
logZip.AddDirectory("/var/log");
logZip.Save(stream);
}
};
}
}
public class ZipModule : NancyModule
{
public ZipModule()
{
Get["/logs"] = _ =>
{
var filename = String.Format("logs-{0}.zip", DateTime.Now.ToUnixTimestamp());
return new LogZipResponse().AsAttachment(filename);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment