Alternate simpler byte[] callback session store

This commit is contained in:
Wizou 2024-02-18 17:41:30 +01:00
parent 288bf7ccf7
commit 125c1caeeb
2 changed files with 10 additions and 0 deletions

View file

@ -94,6 +94,9 @@ namespace WTelegram
})
{ }
public Client(Func<string, string> configProvider, byte[] startSession, Action<byte[]> saveSession)
: this(configProvider, new ActionStore(startSession, saveSession)) { }
/// <summary>Welcome to WTelegramClient! 🙂</summary>
/// <param name="configProvider">Config callback, is queried for: <b>api_id</b>, <b>api_hash</b>, <b>session_pathname</b></param>
/// <param name="sessionStore">if specified, must support initial Length &amp; Read() of a session, then calls to Write() the updated session. Other calls can be ignored</param>

View file

@ -192,4 +192,11 @@ namespace WTelegram
base.Write(_header, 0, 8);
}
}
// QWxp couldn't be bothered to write such a simple SessionStore, so here it is:
internal class ActionStore(byte[] startSession, Action<byte[]> saveSession) : MemoryStream(startSession ?? Array.Empty<byte>())
{
public override void Write(byte[] buffer, int offset, int count) => saveSession(buffer[offset..(offset + count)]);
public override void SetLength(long value) { }
}
}