Exemplo n.º 1
0
 CharacterDevice(IByteDevice backend, Text.Encoding encoding)
 {
     this.backend  = backend;
     this.encoding = encoding;
     this.peeked   = new PeekBuffer(async() =>
     {
         // TODO: Could we use this.encoder.Encode(Func<byte?>)?
         char?result = null;
         var next    = await this.backend.Read();
         if (next.HasValue)
         {
             var buffer = new byte[this.encoding.GetSymbolLength(next.Value)];
             buffer[0]  = next.Value;
             for (var i = 1; i < buffer.Length && (next = await this.backend.Read()).HasValue; i++)
             {
                 buffer[i] = next.Value;
             }
             var r = this.encoding.Decode(buffer);
             if (r.Length > 0)
             {
                 result = r[0];
             }
         }
         return(result);
     });
 }
Exemplo n.º 2
0
 internal ByteDevice(System.IO.Stream backend, Uri.Locator resource, bool dontClose = false) :
     base(backend, resource, dontClose)
 {
     this.peeked = new PeekBuffer(async() =>
     {
         var buffer = new byte[64 * 1024];
         return(await this.backend.ReadAsync(buffer, 0, 1) == 1 ? new Collection.Queue <byte>(buffer) : null);
     });
 }
Exemplo n.º 3
0
 internal BlockDevice(System.IO.Stream backend, Uri.Locator resource, bool dontClose = false) :
     base(backend, resource, dontClose)
 {
     this.peeked = new PeekBuffer(async() =>
     {
         var buffer = new byte[64 * 1024];
         int count  = await this.backend.ReadAsync(buffer, 0, buffer.Length);
         return(count > 0 ? buffer.Slice(0, count) : null);
     });
 }