// // Copyright (c) 2008-2011, Kenneth Bell // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System.Collections.Generic; namespace DiscUtils.Streams { /// /// Interface shared by all buffers. /// /// /// Buffers are very similar to streams, except the buffer has no notion of /// 'current position'. All I/O operations instead specify the position, as /// needed. Buffers also support sparse behaviour. /// public interface IBuffer { /// /// Gets a value indicating whether this buffer can be read. /// bool CanRead { get; } /// /// Gets a value indicating whether this buffer can be modified. /// bool CanWrite { get; } /// /// Gets the current capacity of the buffer, in bytes. /// long Capacity { get; } /// /// Gets the parts of the buffer that are stored. /// /// This may be an empty enumeration if all bytes are zero. IEnumerable Extents { get; } /// /// Reads from the buffer into a byte array. /// /// The offset within the buffer to start reading. /// The destination byte array. /// The start offset within the destination buffer. /// The number of bytes to read. /// The actual number of bytes read. int Read(long pos, byte[] buffer, int offset, int count); /// /// Writes a byte array into the buffer. /// /// The start offset within the buffer. /// The source byte array. /// The start offset within the source byte array. /// The number of bytes to write. void Write(long pos, byte[] buffer, int offset, int count); /// /// Clears bytes from the buffer. /// /// The start offset within the buffer. /// The number of bytes to clear. /// /// Logically equivalent to writing count null/zero bytes to the buffer, some /// implementations determine that some (or all) of the range indicated is not actually /// stored. There is no direct, automatic, correspondence to clearing bytes and them /// not being represented as an 'extent' - for example, the implementation of the underlying /// stream may not permit fine-grained extent storage. /// It is always safe to call this method to 'zero-out' a section of a buffer, regardless of /// the underlying buffer implementation. /// void Clear(long pos, int count); /// /// Flushes all data to the underlying storage. /// void Flush(); /// /// Sets the capacity of the buffer, truncating if appropriate. /// /// The desired capacity of the buffer. void SetCapacity(long value); /// /// Gets the parts of a buffer that are stored, within a specified range. /// /// The offset of the first byte of interest. /// The number of bytes of interest. /// An enumeration of stream extents, indicating stored bytes. IEnumerable GetExtentsInRange(long start, long count); } }