public void When_Comparing_Two_Equal_TDBlobKey_Instances_Equals_Is_True() { var arr = new byte[] { 87, 79, 87, 46, 46, 46 }; var key = new TDBlobKey(arr); var equals = key.Equals(new TDBlobKey(arr)); Assert.That(equals, Is.True); }
public bool StoreBlobStream(Stream stream, TDBlobKey outKey) { FileStream fs = null; try { var tempFileName = System.IO.Path.Combine(Path, TMP_FILE_PREFIX); tempFileName = System.IO.Path.Combine(tempFileName, TMP_FILE_EXTENSION); //would be nice to have this in SL4 profile fs = File.Create(tempFileName); var buffer = new byte[65536]; var lenRead = stream.Read(buffer, 0, 8); using (var sr = new StreamReader(stream)) { } } catch (Exception) { throw; } throw new NotImplementedException(); }
public long GetSizeOfBlob(TDBlobKey key) { var path = GetPathForKey(key); var fileInfo = new FileInfo(path); return fileInfo.OpenText().ReadToEnd().Length; //TODO: make efficient }
public bool StoreBlob(byte[] data, TDBlobKey outKey) { var newKey = GetKeyForBlob(data); outKey.Bytes = newKey.Bytes; var path = GetPathForKey(outKey); var fileStream = new FileStream(path, FileMode.Open); if (fileStream.CanRead) return true; using (var sw = new StreamWriter(fileStream)) { } throw new NotImplementedException(); }
public bool GetKeyForFileName(TDBlobKey outKey, string fileName) { if (!fileName.EndsWith(FILE_EXTENSION)) return false; var rest = System.IO.Path.GetFileNameWithoutExtension(fileName); outKey.Bytes = TDBlobKey.ConvertFromHex(rest); return true; }
public string GetPathForKey(TDBlobKey key) { return Path + System.IO.Path.PathSeparator + TDBlobKey.ConvertToHex(key.Bytes) + FILE_EXTENSION; }
public Stream GetBlobStreamForKey(TDBlobKey key) { var path = GetPathForKey(key); var fileInfo = new FileInfo(path); var fs = new FileStream(fileInfo.FullName, FileMode.Open); if (fs.CanRead) { return fs; } return null; }
public byte[] GetBlobForKey(TDBlobKey key) { var path = GetPathForKey(key); var fileInfo = new FileInfo(path); byte[] result = null; result = GetBytesFromFile(fileInfo); return result; }
public int DeleteBlobExceptWithKeys(IList<TDBlobKey> keysToKeep) { var numDeleted = 0; var files = Directory.GetFiles(Path); foreach (var file in files) { var attachmentKey = new TDBlobKey(); GetKeyForFileName(attachmentKey, file); if (!keysToKeep.Contains(attachmentKey)) { File.Delete(file); ++numDeleted; } } return numDeleted; }
public static TDBlobKey GetKeyForBlobFromFile(FileInfo file) { //TODO: check for failure to create SHA-1? var ha = new SHA1Managed(); var sha1Hash = new byte[40]; var buffer = new byte[65536]; using (var fileStream = new FileStream(file.FullName, FileMode.Open)) { var lenRead = fileStream.Read(buffer, 0, 8); while (lenRead > 0) { lenRead = fileStream.Read(buffer, lenRead, 8); } } //TODO: Revisit Java approach of updating digest on read sha1Hash = ha.ComputeHash(buffer); var result = new TDBlobKey(sha1Hash); return result; }
public static TDBlobKey GetKeyForBlob(byte[] bytes) { //TODO: check for failure to create SHA-1? var ha = new SHA1Managed(); var sha1Hash = new byte[40]; var hashed = ha.ComputeHash(sha1Hash); var result = new TDBlobKey(hashed); return result; }