refactor: ♻️ 2.0 (#3)

This commit is contained in:
2023-12-14 15:03:07 +08:00
committed by GitHub
parent 8c0dbcf1f4
commit cf2988b389
73 changed files with 1157 additions and 371 deletions

View File

@@ -0,0 +1,32 @@
namespace NSExt.Extensions;
/// <summary>
/// StreamExtensions
/// </summary>
public static class StreamExtensions
{
/// <summary>
/// FirstByteIndex
/// </summary>
public static long FirstByteIndex(this Stream me, byte[] findBytes)
{
int data;
while ((data = me.ReadByte()) != -1) {
if (findBytes.Contains((byte)data)) {
return me.Position;
}
}
return -1;
}
/// <summary>
/// IsTextStream
/// </summary>
public static bool IsTextStream(this Stream me)
{
#pragma warning disable IDE0300
return me.FirstByteIndex(new byte[] { 0x00, 0xff }) < 0;
#pragma warning restore IDE0300
}
}