/// <summary> /// get the list of files in the specified bucket. /// </summary> /// <param name="bucketid"></param> /// <returns></returns> public IReadOnlyList <BUCommon.FreezeFile> getFiles(BUCommon.Container cont) { List <BUCommon.FreezeFile> list = new List <BUCommon.FreezeFile>(); B2Net.Models.B2FileList files = null; string startfile = null; do { files = _client.Files.GetList(startfile, null, cont.id).Result; foreach (var f in files.Files) { BUCommon.Hash h = null; try { h = BUCommon.Hash.FromString("SHA1", f.ContentSHA1); } catch (FormatException fe) { h = BUCommon.Hash.Create("", new byte[] {}); } var ff = new BUCommon.FreezeFile { path = f.FileName , uploaded = f.UploadTimestampDate , fileID = f.FileId , storedHash = h , mimeType = f.ContentType , serviceInfo = f.Action , container = cont }; if (f.FileInfo.ContainsKey(LAST_MOD_MILLIS)) { } if (f.FileInfo.ContainsKey(LOCALHASH)) { ff.enchash = f.FileInfo[LOCALHASH]; } list.Add(ff); } startfile = files.NextFileName; } while (startfile != null); return(list); }
public void B2SHA1() { var destHash = "eeea523c2b2dd9415c657556e45f73be993d7979"; var hash = BUCommon.Hash.FromString("SHA1", destHash); var fe = new BackupLib.FileEncrypt(null); BUCommon.Hash filehash = null; byte[] filebytes = null; { var strm = new System.IO.FileStream(@"C:\tmp\b2test\cont1\2016\1231-newyears\DSC06560.ARW", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); filehash = fe.hashContents("SHA1", strm); strm.Seek(0, System.IO.SeekOrigin.Begin); var mstr = new System.IO.MemoryStream(); byte[] buff = new byte[8192]; int len = 0; while (true) { len = strm.Read(buff, 0, buff.Length); if (len > 0) { mstr.Write(buff, 0, len); } if (len == 0) { break; } } strm.Dispose(); strm = null; filebytes = mstr.ToArray(); mstr.Dispose(); mstr = null; } string b2nethash = B2Net.Utilities.GetSHA1Hash(filebytes); Assert.That(hash.base64, Is.EqualTo(filehash.base64)); }