wasSharp – Diff between revs 24 and 25

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 24 Rev 25
Line 37... Line 37...
37 { 37 {
38 return Path.GetInvalidFileNameChars() 38 return Path.GetInvalidFileNameChars()
39 .Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty)); 39 .Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty));
40 } 40 }
Line -... Line 41...
-   41  
-   42 ///////////////////////////////////////////////////////////////////////////
-   43 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
-   44 ///////////////////////////////////////////////////////////////////////////
-   45 /// <summary>
-   46 /// Compress a stream using Deflate compression.
-   47 /// </summary>
-   48 /// <param name="uncompressedSourceStream">the stream to compress</param>
-   49 /// <param name="compressedDestinationStream">the stream to write the compressed stream to</param>
-   50 /// <param name="leaveOpen">whether to leave the compression stream open</param>
41   51 /// <returns>an awaitable Task</returns>
42 public static async Task DeflateCompress(this Stream uncompressedSourceStream, 52 public static async Task DeflateCompress(this Stream uncompressedSourceStream,
43 Stream compressedDestinationStream, bool leaveOpen = false) 53 Stream compressedDestinationStream, bool leaveOpen = false)
44 { 54 {
45 using ( 55 using (
Line 48... Line 58...
48 { 58 {
49 await uncompressedSourceStream.CopyToAsync(compressionStream); 59 await uncompressedSourceStream.CopyToAsync(compressionStream);
50 } 60 }
51 } 61 }
Line -... Line 62...
-   62  
-   63 ///////////////////////////////////////////////////////////////////////////
-   64 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
-   65 ///////////////////////////////////////////////////////////////////////////
-   66 /// <summary>
-   67 /// Decompress a Deflate-compressed stream.
-   68 /// </summary>
-   69 /// <param name="compressedSourceStream">the compressed stream to decompress</param>
-   70 /// <param name="uncompressedDestinationStream">the stream to write the decompressed stream to</param>
-   71 /// <param name="leaveOpen">whether to leave the stream open after decompression</param>
52   72 /// <returns>an awaitable Task</returns>
53 public static async Task DeflateDecompress(this Stream compressedSourceStream, 73 public static async Task DeflateDecompress(this Stream compressedSourceStream,
54 Stream uncompressedDestinationStream, bool leaveOpen = false) 74 Stream uncompressedDestinationStream, bool leaveOpen = false)
55 { 75 {
56 using ( 76 using (
Line 59... Line 79...
59 { 79 {
60 await decompressionStream.CopyToAsync(uncompressedDestinationStream); 80 await decompressionStream.CopyToAsync(uncompressedDestinationStream);
61 } 81 }
62 } 82 }
Line -... Line 83...
-   83  
-   84 ///////////////////////////////////////////////////////////////////////////
-   85 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
-   86 ///////////////////////////////////////////////////////////////////////////
-   87 /// <summary>
-   88 /// Compress a stream using GZip compression.
-   89 /// </summary>
-   90 /// <param name="uncompressedSourceStream">the stream to compress</param>
-   91 /// <param name="compressedDestinationStream">the stream to write the compressed stream to</param>
-   92 /// <param name="leaveOpen">whether to leave the stream open after compressing</param>
63   93 /// <returns>an awaitable Task</returns>
64 public static async Task GZipCompress(this Stream uncompressedSourceStream, Stream compressedDestinationStream, 94 public static async Task GZipCompress(this Stream uncompressedSourceStream, Stream compressedDestinationStream,
65 bool leaveOpen = false) 95 bool leaveOpen = false)
66 { 96 {
67 using ( 97 using (
Line 70... Line 100...
70 { 100 {
71 await uncompressedSourceStream.CopyToAsync(compressionStream); 101 await uncompressedSourceStream.CopyToAsync(compressionStream);
72 } 102 }
73 } 103 }
Line -... Line 104...
-   104  
-   105 ///////////////////////////////////////////////////////////////////////////
-   106 // Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
-   107 ///////////////////////////////////////////////////////////////////////////
-   108 /// <summary>
-   109 /// Decompress a GZiped stream.
-   110 /// </summary>
-   111 /// <param name="compressedSourceStream">the stream to decompress</param>
-   112 /// <param name="uncompressedDestinationStream">the stream to write the decompressed stream to</param>
-   113 /// <param name="leaveOpen">whether the decompression stream should be left open</param>
74   114 /// <returns>an awaitable Task</returns>
75 public static async Task GZipDecompress(this Stream compressedSourceStream, Stream uncompressedDestinationStream, 115 public static async Task GZipDecompress(this Stream compressedSourceStream, Stream uncompressedDestinationStream,
76 bool leaveOpen = false) 116 bool leaveOpen = false)
77 { 117 {
78 using ( 118 using (
79 var decompressionStream = new GZipStream(compressedSourceStream, CompressionMode.Decompress, leaveOpen)) 119 var decompressionStream = new GZipStream(compressedSourceStream, CompressionMode.Decompress, leaveOpen))
80 { 120 {
81 await decompressionStream.CopyToAsync(uncompressedDestinationStream); 121 await decompressionStream.CopyToAsync(uncompressedDestinationStream);
82 } 122 }
Line 83... Line -...
83 } -  
84   -  
85 public static string MimeType(string fileName, char extensionSeparator = '.') -  
86 { -  
87 switch (fileName.Split('.').Last().ToUpperInvariant()) -  
88 { -  
89 case "AVI": -  
90 return "video/x-msvideo"; -  
91 case "CSS": -  
92 return "text/css"; -  
93 case "DOC": -  
94 return "application/msword"; -  
95 case "GIF": -  
96 return "image/gif"; -  
97 case "HTM": -  
98 case "HTML": -  
99 return "text/html"; -  
100 case "JPG": -  
101 case "JPEG": -  
102 return "image/jpeg"; -  
103 case "JS": -  
104 return "application/x-javascript"; -  
105 case "MP3": -  
106 return "audio/mpeg"; -  
107 case "PNG": -  
108 return "image/png"; -  
109 case "PDF": -  
110 return "application/pdf"; -  
111 case "PPT": -  
112 return "application/vnd.ms-powerpoint"; -  
113 case "ZIP": -  
114 return "application/zip"; -  
115 case "TXT": -  
116 return "text/plain"; -  
117 case "XML": -  
118 return "text/xml"; -  
119 case "SQLITE": -  
120 return "application/x-sqlite3"; -  
121 default: -  
122 return "application/octet-stream"; -  
123 } -  
124 } 123 }
125   124  
126 /////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////
127 // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // 126 // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 //
128 /////////////////////////////////////////////////////////////////////////// 127 ///////////////////////////////////////////////////////////////////////////