|
7 | 7 |
|
8 | 8 | namespace ServiceStack.VirtualPath |
9 | 9 | { |
10 | | - public interface IWriteableVirtualPathProvider |
11 | | - { |
12 | | - void AddFile(string filePath, string contents); |
13 | | - } |
14 | | - |
15 | 10 | /// <summary> |
16 | 11 | /// In Memory repository for files. Useful for testing. |
17 | 12 | /// </summary> |
@@ -44,16 +39,21 @@ protected override void Initialize() |
44 | 39 | { |
45 | 40 | } |
46 | 41 |
|
47 | | - public void AddFile(string filePath, string contents) |
48 | | - { |
49 | | - rootDirectory.AddFile(filePath, contents); |
50 | | - } |
51 | | - |
52 | 42 | public override IVirtualFile GetFile(string virtualPath) |
53 | 43 | { |
54 | 44 | return rootDirectory.GetFile(virtualPath) |
55 | 45 | ?? base.GetFile(virtualPath); |
56 | 46 | } |
| 47 | + |
| 48 | + public void AddFile(string filePath, string textContents) |
| 49 | + { |
| 50 | + rootDirectory.AddFile(filePath, textContents); |
| 51 | + } |
| 52 | + |
| 53 | + public void AddFile(string filePath, Stream stream) |
| 54 | + { |
| 55 | + rootDirectory.AddFile(filePath, stream); |
| 56 | + } |
57 | 57 | } |
58 | 58 |
|
59 | 59 | public class InMemoryVirtualDirectory : AbstractVirtualDirectoryBase |
@@ -134,20 +134,32 @@ protected override IVirtualDirectory GetDirectoryFromBackingDirectoryOrDefault(s |
134 | 134 | return null; |
135 | 135 | } |
136 | 136 |
|
137 | | - static readonly char[] DirSeps = new[] { '\\', '/' }; |
138 | 137 | public void AddFile(string filePath, string contents) |
139 | 138 | { |
140 | 139 | filePath = StripBeginningDirectorySeparator(filePath); |
141 | | - this.files.Add(new InMemoryVirtualFile(VirtualPathProvider, this) { |
| 140 | + this.files.Add(new InMemoryVirtualFile(VirtualPathProvider, this) |
| 141 | + { |
142 | 142 | FilePath = filePath, |
143 | 143 | FileName = filePath.Split(DirSeps).Last(), |
144 | 144 | TextContents = contents, |
145 | 145 | }); |
146 | 146 | } |
147 | 147 |
|
| 148 | + public void AddFile(string filePath, Stream stream) |
| 149 | + { |
| 150 | + filePath = StripBeginningDirectorySeparator(filePath); |
| 151 | + this.files.Add(new InMemoryVirtualFile(VirtualPathProvider, this) |
| 152 | + { |
| 153 | + FilePath = filePath, |
| 154 | + FileName = filePath.Split(DirSeps).Last(), |
| 155 | + ByteContents = stream.ReadFully(), |
| 156 | + }); |
| 157 | + } |
| 158 | + |
| 159 | + static readonly char[] DirSeps = new[] { '\\', '/' }; |
148 | 160 | private static string StripBeginningDirectorySeparator(string filePath) |
149 | 161 | { |
150 | | - if (String.IsNullOrEmpty(filePath)) |
| 162 | + if (string.IsNullOrEmpty(filePath)) |
151 | 163 | return filePath; |
152 | 164 |
|
153 | 165 | if (DirSeps.Any(d => filePath[0] == d)) |
|
0 commit comments