ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | List of all members
ImageResizer.Plugins.DiskCache.UrlHasher Class Reference

Public Member Functions

string hash (string data, int subfolders, string dirSeparator)
 Builds a key for the cached version, using the hashcode of the normalized URL. if subfolders > 1, dirSeparator will be used to separate the subfolder and the key. No extension is appended. I.e, a13514\124211ab132592 or 12412ababc12141 More...
 

Protected Member Functions

string getSubfolder (byte[] hash, int subfolders)
 Returns a string for the subfolder name. The bits used are from the end of the hash - this should make the hashes in each directory more unique, and speed up performance (8.3 filename calculations are slow when lots of files share the same first 6 chars. Returns null if not configured. Rounds subfolders up to the nearest power of two. More...
 
string Base16Encode (byte[] bytes)
 

Detailed Description

Definition at line 11 of file UrlHasher.cs.

Member Function Documentation

string ImageResizer.Plugins.DiskCache.UrlHasher.getSubfolder ( byte[]  hash,
int  subfolders 
)
inlineprotected

Returns a string for the subfolder name. The bits used are from the end of the hash - this should make the hashes in each directory more unique, and speed up performance (8.3 filename calculations are slow when lots of files share the same first 6 chars. Returns null if not configured. Rounds subfolders up to the nearest power of two.

Parameters
hash
subfolders
Returns

Definition at line 48 of file UrlHasher.cs.

48  {
49  int bits = (int)Math.Ceiling(Math.Log(subfolders, 2)); //Log2 to find the number of bits. round up.
50  Debug.Assert(bits > 0);
51  Debug.Assert(bits <= hash.Length * 8);
52 
53  byte[] subfolder = new byte[(int)Math.Ceiling((double)bits / 8.0)]; //Round up to bytes.
54  Array.Copy(hash, hash.Length - subfolder.Length, subfolder, 0, subfolder.Length);
55  subfolder[0] = (byte)((int)subfolder[0] >> ((subfolder.Length * 8) - bits)); //Set extra bits to 0.
56  return Base16Encode(subfolder);
57 
58  }
string hash(string data, int subfolders, string dirSeparator)
Builds a key for the cached version, using the hashcode of the normalized URL. if subfolders &gt; 1...
Definition: UrlHasher.cs:25
string ImageResizer.Plugins.DiskCache.UrlHasher.hash ( string  data,
int  subfolders,
string  dirSeparator 
)
inline

Builds a key for the cached version, using the hashcode of the normalized URL. if subfolders > 1, dirSeparator will be used to separate the subfolder and the key. No extension is appended. I.e, a13514\124211ab132592 or 12412ababc12141

Parameters
data
subfolders
dirSeparator
Returns

Definition at line 25 of file UrlHasher.cs.

25  {
26 
27  SHA256 h = System.Security.Cryptography.SHA256.Create();
28  byte[] hash = h.ComputeHash(new System.Text.UTF8Encoding().GetBytes(data));
29 
30  //If configured, place files in subfolders.
31  string subfolder = "";
32  if (subfolders > 1) {
33  subfolder = getSubfolder(hash, subfolders) + dirSeparator;
34  }
35 
36  //Can't use base64 hash... filesystem has case-insensitive lookup.
37  //Would use base32, but too much code to bloat the resizer. Simple base16 encoding is fine
38  return subfolder + Base16Encode(hash);
39  }
string hash(string data, int subfolders, string dirSeparator)
Builds a key for the cached version, using the hashcode of the normalized URL. if subfolders &gt; 1...
Definition: UrlHasher.cs:25
string getSubfolder(byte[] hash, int subfolders)
Returns a string for the subfolder name. The bits used are from the end of the hash - this should mak...
Definition: UrlHasher.cs:48

The documentation for this class was generated from the following file: