예제 #1
0
 public MemoryStream AsSeekableStream()
 {
     if (ResultStream.CanSeek)
     {
         ResultStream.Seek(0, SeekOrigin.Begin);
     }
     using (ResultStream) {
         var ms = new MemoryStream();
         ResultStream.CopyTo(ms);
         ResultStream.Flush();
         return(ms);
     }
 }
예제 #2
0
        //public Stream AsRawStream() {
        //    var rawStream = new MemoryStream();
        //    using (var writer = new StreamWriter(rawStream, new UTF8Encoding(), 8192, true)) {
        //        writer.WriteLine($"HTTP/1.1 {StatusCode} {StatusDescription}");
        //        lock (this.Headers) {
        //            this.Headers.ForEach(header => {
        //                writer.WriteLine();
        //            });
        //        }
        //        writer.WriteLine();
        //    }
        //    ResultStream.CopyTo(rawStream);
        //    rawStream.Seek(0, SeekOrigin.Begin);
        //    return rawStream;
        //}

        public byte[] AsBuffer()
        {
            if (ResultStream.CanSeek)
            {
                ResultStream.Seek(0, SeekOrigin.Begin);
            }
            byte[] bytes;
            if (ResultStream is MemoryStream rsms)
            {
                bytes = rsms.ToArray();
            }
            else
            {
                using (var ms = new MemoryStream()) {
                    ResultStream.CopyTo(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    bytes = ms.ToArray();
                }
            }
            return(bytes);
        }
예제 #3
0
 public override void Output(HttpListenerResponse output)
 {
     output.StatusCode  = StatusCode;
     output.ContentType = ContentType;
     ResultStream.CopyTo(output.OutputStream);
 }