summaryrefslogtreecommitdiff
path: root/FireBase/Streaming/NonBlockingStreamReader.cs
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-06-11 23:38:13 +0200
committerDennis Kobert <d-kobert@web.de>2019-06-11 23:38:13 +0200
commit2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (patch)
treec3b34ccb2737e347a73768536895cbbaab13cc01 /FireBase/Streaming/NonBlockingStreamReader.cs
parentec991104f56e90d7bb2878da2fe6ed4e585dfc46 (diff)
parentaf74efccf8d21e6151022b71f3cacd3fa83024ee (diff)
Merge branch 'rework-backend'
Diffstat (limited to 'FireBase/Streaming/NonBlockingStreamReader.cs')
-rw-r--r--FireBase/Streaming/NonBlockingStreamReader.cs60
1 files changed, 0 insertions, 60 deletions
diff --git a/FireBase/Streaming/NonBlockingStreamReader.cs b/FireBase/Streaming/NonBlockingStreamReader.cs
deleted file mode 100644
index 2ac83fd..0000000
--- a/FireBase/Streaming/NonBlockingStreamReader.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-namespace Firebase.Database.Streaming
-{
- using System.IO;
- using System.Text;
-
- /// <summary>
- /// When a regular <see cref="StreamReader"/> is used in a UWP app its <see cref="StreamReader.ReadLine"/> method tends to take a long
- /// time for data larger then 2 KB. This extremly simple implementation of <see cref="TextReader"/> can be used instead to boost performance
- /// in your UWP app. Use <see cref="FirebaseOptions"/> to inject an instance of this class into your <see cref="FirebaseClient"/>.
- /// </summary>
- public class NonBlockingStreamReader : TextReader
- {
- private const int DefaultBufferSize = 16000;
-
- private readonly Stream stream;
- private readonly byte[] buffer;
- private readonly int bufferSize;
-
- private string cachedData;
-
- public NonBlockingStreamReader(Stream stream, int bufferSize = DefaultBufferSize)
- {
- this.stream = stream;
- this.bufferSize = bufferSize;
- this.buffer = new byte[bufferSize];
-
- this.cachedData = string.Empty;
- }
-
- public override string ReadLine()
- {
- var currentString = this.TryGetNewLine();
-
- while (currentString == null)
- {
- var read = this.stream.Read(this.buffer, 0, this.bufferSize);
- var str = Encoding.UTF8.GetString(buffer, 0, read);
-
- cachedData += str;
- currentString = this.TryGetNewLine();
- }
-
- return currentString;
- }
-
- private string TryGetNewLine()
- {
- var newLine = cachedData.IndexOf('\n');
-
- if (newLine >= 0)
- {
- var r = cachedData.Substring(0, newLine + 1);
- this.cachedData = cachedData.Remove(0, r.Length);
- return r.Trim();
- }
-
- return null;
- }
- }
-}