Ejemplo n.º 1
0
        public static byte[] ReadAllBytes(this IVirtualFile file)
        {
            using var stream = file.OpenRead();
            var bytes = stream.ReadFully();

            return(bytes);
        }
Ejemplo n.º 2
0
        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);
     }
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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 },
            };
        }
Ejemplo n.º 8
0
        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 },
            };
        }
Ejemplo n.º 9
0
        public static byte[] ReadAllBytes(this IVirtualFile file)
        {
            var bytes = file.OpenRead().ReadFully();

            return(bytes);
        }