BytesToString()
This commit is contained in:
parent
e2d0fb8a03
commit
dcc1ad3e17
@ -42,7 +42,7 @@ namespace DTLib.Filesystem
|
||||
return output;
|
||||
}
|
||||
|
||||
public static string ReadAllText(string file) => FrameworkFix.ToString(ReadAllBytes(file));
|
||||
public static string ReadAllText(string file) => ReadAllBytes(file).BytesToString();
|
||||
|
||||
public static void WriteAllBytes(string file, byte[] content)
|
||||
{
|
||||
|
||||
@ -105,7 +105,7 @@ namespace DTLib
|
||||
|
||||
public static Encoding UTF8 = new UTF8Encoding(false);
|
||||
// байты в кодировке UTF8 в строку
|
||||
public static string ToString(this byte[] bytes) => UTF8.GetString(bytes);
|
||||
public static string BytesToString(this byte[] bytes) => UTF8.GetString(bytes);
|
||||
|
||||
// хеш в виде массива байт в строку (хеш изначально не в кодировке UTF8, так что метод выше не работает с ним)
|
||||
public static string HashToString(this byte[] hash)
|
||||
@ -183,5 +183,24 @@ namespace DTLib
|
||||
o.Add(b.ToString());
|
||||
return o;
|
||||
}
|
||||
|
||||
// разбивает на части указанной длины
|
||||
public static List<string> Split(this string s, int length)
|
||||
{
|
||||
List<string> parts = new();
|
||||
int max = (s.Length/length).Truncate();
|
||||
for(int i = 0; i<max; i++)
|
||||
parts.Add(s.Substring(i*length, length));
|
||||
if(max*length!=s.Length) parts.Add(s.Substring(max*length, s.Length-max*length));
|
||||
return parts;
|
||||
}
|
||||
|
||||
public static T If<T>(this T input, bool condition, Func<T,T> if_true, Func<T,T> if_false)
|
||||
{
|
||||
if(condition)
|
||||
return if_true(input);
|
||||
else
|
||||
return if_false(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ namespace DTLib.Network
|
||||
Mutex.Execute(() =>
|
||||
{
|
||||
BytesDownloaded=0;
|
||||
Filesize=FrameworkFix.ToString(MainSocket.GetPackage()).ToUInt();
|
||||
Filesize=MainSocket.GetPackage().BytesToString().ToUInt();
|
||||
MainSocket.SendPackage("ready".ToBytes());
|
||||
int packagesCount = 0;
|
||||
byte[] buffer = new byte[5120];
|
||||
@ -144,7 +144,7 @@ namespace DTLib.Network
|
||||
if(!dirOnServer.EndsWith("\\"))
|
||||
dirOnServer+="\\";
|
||||
Debug("b", "downloading manifest <", "c", dirOnServer+"manifest.dtsod", "b", ">\n");
|
||||
var manifest = new Dtsod.DtsodV22(FrameworkFix.ToString(DownloadFileToMemory(dirOnServer+"manifest.dtsod")));
|
||||
var manifest = new Dtsod.DtsodV22(DownloadFileToMemory(dirOnServer+"manifest.dtsod").BytesToString());
|
||||
Debug("g", $"found {manifest.Values.Count} files in manifest\n");
|
||||
var hasher = new Hasher();
|
||||
foreach(string fileOnServer in manifest.Keys)
|
||||
|
||||
@ -55,7 +55,7 @@ namespace DTLib.Network
|
||||
// получает пакет и выбрасывает исключение, если пакет не соответствует образцу
|
||||
public static void GetAnswer(this Socket socket, string answer)
|
||||
{
|
||||
string rec = FrameworkFix.ToString(socket.GetPackage());
|
||||
string rec = socket.GetPackage().BytesToString();
|
||||
if(rec!=answer)
|
||||
throw new Exception($"GetAnswer() error: invalid answer: <{rec}>");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user