Revision cfed7823 trunk/Pithos.Core/Agents/FileInfoExtensions.cs
b/trunk/Pithos.Core/Agents/FileInfoExtensions.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics.Contracts; |
|
3 | 4 |
using System.Linq; |
4 | 5 |
using System.Text; |
5 | 6 |
using System.IO; |
... | ... | |
13 | 14 |
{ |
14 | 15 |
public static string AsRelativeTo(this FileInfo fileInfo,string path ) |
15 | 16 |
{ |
17 |
if (String.IsNullOrWhiteSpace(path)) |
|
18 |
throw new ArgumentNullException("path"); |
|
19 |
Contract.EndContractBlock(); |
|
20 |
|
|
21 |
|
|
16 | 22 |
if (!path.EndsWith("\\")) |
17 | 23 |
path=path.ToLower() + "\\"; |
18 | 24 |
int pathLength = path.Length; |
... | ... | |
29 | 35 |
|
30 | 36 |
public static string AsRelativeUrlTo(this FileInfo fileInfo,string path ) |
31 | 37 |
{ |
38 |
if (String.IsNullOrWhiteSpace(path)) |
|
39 |
throw new ArgumentNullException("path"); |
|
40 |
Contract.EndContractBlock(); |
|
32 | 41 |
|
33 | 42 |
var relativePath = fileInfo.AsRelativeTo(path); |
34 | 43 |
var replacedSlashes = relativePath.Replace("\\","/"); |
... | ... | |
38 | 47 |
|
39 | 48 |
public static string RelativeUriToFilePath(this Uri uri) |
40 | 49 |
{ |
41 |
return RelativeUrlToFilePath(uri.ToString()); |
|
42 |
} |
|
43 |
|
|
44 |
public static string RelativeUrlToFilePath(this string url) |
|
45 |
{ |
|
46 |
var unescaped=Uri.UnescapeDataString(url); |
|
50 |
var unescaped = Uri.UnescapeDataString(uri.ToString()); |
|
47 | 51 |
var path = unescaped.Replace("/", "\\"); |
48 | 52 |
return path; |
49 | 53 |
} |
50 | 54 |
|
55 |
|
|
51 | 56 |
public static int Read(this FileInfo fileInfo,byte[] buffer,int offset,int count) |
52 | 57 |
{ |
53 | 58 |
//Open the stream only long enough to read a block |
... | ... | |
90 | 95 |
|
91 | 96 |
public static string CalculateHash(this FileInfo info,int blockSize,string algorithm) |
92 | 97 |
{ |
98 |
if (info==null) |
|
99 |
throw new ArgumentNullException("info"); |
|
100 |
if (String.IsNullOrWhiteSpace(info.FullName)) |
|
101 |
throw new ArgumentException("info"); |
|
102 |
if (blockSize<=0) |
|
103 |
throw new ArgumentOutOfRangeException("blockSize",blockSize,"blockSize must be greater than 0"); |
|
104 |
if (String.IsNullOrWhiteSpace(algorithm)) |
|
105 |
throw new ArgumentNullException("algorithm"); |
|
106 |
Contract.EndContractBlock(); |
|
107 |
|
|
93 | 108 |
if (info.Length <= blockSize) |
94 | 109 |
return Signature.CalculateMD5(info.FullName); |
95 | 110 |
else |
Also available in: Unified diff