LZMA.Master.LZMA.SRes LZMA.Master.LZMA.ISeqInStream.Read(LZMA.P <byte> buf, ref long size) { System.Diagnostics.Debug.Assert(size > 0); if (mCompleted) { size = 0; return(LZMA.Master.LZMA.SZ_OK); } var capacity = size < Int32.MaxValue ? (int)size : Int32.MaxValue; int fetched; try { fetched = mStream.ReadAsync(buf.mBuffer, buf.mOffset, capacity, StreamMode.Partial).GetAwaiter().GetResult(); } catch (OperationCanceledException) { size = 0; return(LZMA.Master.LZMA.SZ_ERROR_FAIL); } if (fetched < 0 || fetched > capacity) { throw new InvalidOperationException("IInputStream.ReadAsync returned an invalid result."); } if (fetched == 0) { mCompleted = true; } size = fetched; return(LZMA.Master.LZMA.SZ_OK); }
long LZMA.Master.LZMA.ISeqOutStream.Write(LZMA.P <byte> buf, long size) { System.Diagnostics.Debug.Assert(size > 0); var buffer = buf.mBuffer; var offset = buf.mOffset; var result = size; while (size > Int32.MaxValue) { int written; try { written = mStream.WriteAsync(buffer, offset, Int32.MaxValue, StreamMode.Partial).GetAwaiter().GetResult(); } catch (OperationCanceledException) { return(0); } if (written <= 0) { throw new InvalidOperationException("IOutputStream.WriteAsync returned an invalid result."); } offset += written; size -= written; } if (size > 0) { int written; try { written = mStream.WriteAsync(buffer, offset, (int)size, StreamMode.Complete).GetAwaiter().GetResult(); } catch (OperationCanceledException) { return(0); } if (written != size) { throw new InvalidOperationException("IOutputStream.WriteAsync returned an invalid result."); } } return(result); }