Пример #1
0
        // Read some data at a specified position within a data block
        // into a buffer in memory
        internal bool ReadData(ulong position, // Position within the block
                               uint size,      // Size of the memory buffer
                               byte[] buffer)  // Pointer to memory buffer
        {
            // Check to see if the position from which data is to be read
            // is within the bounds of the data block
            if (length > position)
            {
                // Compute the file offset and how much data to physically read from disk
                ulong fileoffset = offset + position;
                uint  want       = (uint)Math.Min((ulong)size, length - position);

                if (want < buffer.Length)
                {
                    Array.Clear(buffer, 0, buffer.Length);
                }

                // Read the data from the file into the buffer
                if (!diskfile.Read(fileoffset, buffer, want))
                {
                    return(false);
                }

                // If the read extends beyond the end of the data block,
                // then the rest of the buffer is zeroed.
            }
            else
            {
                // Zero the whole buffer
                buffer = new byte[size];
            }

            return(true);
        }