private FileNode Download(string path, bool check = false) { if (_masterCon == null) return null; var fullpath = Path.Combine(WorkDir, path); //Debug.Assert(!File.Exists(fullpath)); var gw = new StorageClient(_taskName, _masterCon); using(var f = File.Create(fullpath, FileNode.MaxCachedSize)) { long pos = 0; while (true) { byte[] buf = gw.ReadData(path, pos, FileNode.MaxCachedSize); f.Write(buf, 0, buf.Length); pos += buf.Length; if (buf.Length != FileNode.MaxCachedSize) break; } f.Flush(); } var ret = PreRead(path); if (check) { var len = gw.GetSize(path); var hs = gw.GetHash(path); Debug.Assert(len.HasValue && hs.HasValue); if (ret.Length != len.Value) throw new Exception("File '" + path + "' corrupted: length"); if (ret.Hash != hs.Value) throw new Exception("File '" + path + "' corrupted: hash wrong"); } return ret; }