public static byte[] ReadAllBytes(this IVirtualFile file) { using var stream = file.OpenRead(); var bytes = stream.ReadFully(); return(bytes); }
public HttpResult(IVirtualFile fileResponse, string contentType = null, bool asAttachment = false) : this(null, contentType ?? MimeTypes.GetMimeType(fileResponse.Name), HttpStatusCode.OK) { if (fileResponse == null) { throw new ArgumentNullException(nameof(fileResponse)); } this.AllowsPartialResponse = true; this.LastModified = fileResponse.LastModified; this.VirtualFile = fileResponse; this.ResponseStream = fileResponse.OpenRead(); if (!asAttachment) { return; } var headerValue = $"attachment; {HttpExt.GetDispositionFileName(fileResponse.Name)}; size={fileResponse.Length}; modification-date={fileResponse.LastModified.ToString("R").Replace(",", "")}"; this.Headers = new Dictionary <string, string> { { HttpHeaders.ContentDisposition, headerValue }, }; }
public ZipVirtualPathProvider(IVirtualFile file) { VirtualFile = file; using (var stream = file.OpenRead()) { Zip = ZipFile.Read(stream); } }
public static byte[] ReadAllBytes(this IVirtualFile file) { var bytes = new List <byte>(); using (var stream = file.OpenRead()) { return(stream.ReadToEnd()); } }
public static void WriteFile(this IVirtualPathProvider pathProvider, IVirtualFile file, string filePath = null) { var writableFs = pathProvider as IVirtualFiles; if (writableFs == null) throw new InvalidOperationException(ErrorNotWritable.Fmt(pathProvider.GetType().Name)); using (var stream = file.OpenRead()) { writableFs.WriteFile(filePath ?? file.VirtualPath, stream); } }
public HttpResult(IVirtualFile fileResponse, string contentType = null, bool asAttachment = false) : this(null, contentType ?? MimeTypes.GetMimeType(fileResponse.Name), HttpStatusCode.OK) { this.AllowsPartialResponse = true; this.ResponseStream = fileResponse.OpenRead(); if (!asAttachment) return; var headerValue = $"attachment; filename=\"{fileResponse.Name}\"; size={fileResponse.Length}; modification-date={fileResponse.LastModified.ToString("R").Replace(",", "")}"; this.Headers = new Dictionary<string, string> { { HttpHeaders.ContentDisposition, headerValue }, }; }
public HttpResult(IVirtualFile fileResponse, string contentType = null, bool asAttachment = false) : this(null, contentType ?? MimeTypes.GetMimeType(fileResponse.Name), HttpStatusCode.OK) { this.AllowsPartialResponse = true; this.ResponseStream = fileResponse.OpenRead(); if (!asAttachment) { return; } var headerValue = "attachment; " + "filename=\"" + fileResponse.Name + "\"; " + "size=" + fileResponse.Length + "; " + "modification-date=" + fileResponse.LastModified.ToString("R").Replace(",", ""); this.Headers = new Dictionary <string, string> { { HttpHeaders.ContentDisposition, headerValue }, }; }
public static byte[] ReadAllBytes(this IVirtualFile file) { var bytes = file.OpenRead().ReadFully(); return(bytes); }