forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileExtensions.cs
More file actions
55 lines (48 loc) · 1.54 KB
/
Copy pathFileExtensions.cs
File metadata and controls
55 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.IO;
using ServiceStack.IO;
using ServiceStack.Text;
using ServiceStack.Web;
namespace ServiceStack
{
public static class FileExtensions
{
public static void SaveTo(this IHttpFile httpFile, string filePath)
{
using (var sw = new StreamWriter(File.Create(filePath)))
{
httpFile.InputStream.WriteTo(sw.BaseStream);
}
}
public static void SaveTo(this IHttpFile httpFile, IVirtualFiles vfs, string filePath)
{
vfs.WriteFile(filePath, httpFile.InputStream);
}
public static void WriteTo(this IHttpFile httpFile, Stream stream)
{
httpFile.InputStream.WriteTo(stream);
}
public static string MapServerPath(this string relativePath)
{
return HostContext.IsAspNetHost
? relativePath.MapHostAbsolutePath()
: relativePath.MapAbsolutePath();
}
public static bool IsRelativePath(this string relativeOrAbsolutePath)
{
return !relativeOrAbsolutePath.Contains(":")
&& !relativeOrAbsolutePath.StartsWith("/")
&& !relativeOrAbsolutePath.StartsWith("\\");
}
public static byte[] ReadFully(this FileInfo file)
{
using (var fs = file.OpenRead())
{
return fs.ReadFully();
}
}
public static string ReadAllText(this FileInfo file)
{
return file.ReadFully().FromUtf8Bytes();
}
}
}