async Tasks.Task <byte?> IByteInDevice.Read() { byte?result = null; Tasks.Task done; lock (this.peekedLock) { done = this.peeked = this.Peek().Then(p => { Collection.IBlock <byte> r = null; if (p.NotNull() && p.Count > 0) { result = p[0]; r = p.Count > 1 ? p.Slice(1) : null; } else { result = null; } return(r); }); } await done; return(result); }
public async Tasks.Task <bool> Write(Collection.IBlock <byte> buffer) { bool result = true; try { int seek = this.peeked.Reset(); if (seek != 0) { await this.Seek(seek); } byte[] array = buffer.AsArray(); await this.backend.WriteAsync(array, 0, array.Length); if (this.AutoFlush) { await this.Flush(); } } catch (System.Exception) { result = false; } return(result); }
public async Tasks.Task <bool> Write(Collection.IBlock <byte> buffer) { await this.Flush(); bool result = true; try { byte[] array = buffer.ToArray(); // TODO: fix this with some kind of array-slice api await this.stream.WriteAsync(array, 0, array.Length); if (this.AutoFlush) { await this.Flush(); } } catch (System.Exception) { result = false; } return(result); }