Created
March 31, 2015 14:53
-
-
Save tomsseisums/16108aeb0c656be9ce48 to your computer and use it in GitHub Desktop.
Zip as a stream in NancyFX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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