public void GetResourceData(String resourceName, out String resourceType, out byte[] resourceData)
{
if (resourceName == null)
throw new ArgumentNullException("resourceName");
if (_resCache == null)
throw new InvalidOperationException(Environment.GetResourceString("ResourceReaderIsClosed"));
// Get the type information from the data section. Also,
// sort all of the data section's indexes to compute length of
// the serialized data for this type (making sure to subtract
// off the length of the type code).
int[] dataPositions = new int[_numResources];
int dataPos = FindPosForResource(resourceName);
if( dataPos == -1) {
throw new ArgumentException(Environment.GetResourceString("Arg_ResourceNameNotExist", resourceName));
}
lock(this) {
// Read all the positions of data within the data section.
for(int i=0; i<_numResources; i++) {
_store.BaseStream.Position = _nameSectionOffset + GetNamePosition(i);
// Skip over name of resource
int numBytesToSkip = _store.Read7BitEncodedInt();
_store.BaseStream.Position += numBytesToSkip;
dataPositions[i] = _store.ReadInt32();
}
Array.Sort(dataPositions);
int index = Array.BinarySearch(dataPositions, dataPos);
BCLDebug.Assert(index >= 0 && index < _numResources, "Couldn't find data position within sorted data positions array!");
long nextData = (index < _numResources - 1) ? dataPositions[index + 1] + _dataSectionOffset : _store.BaseStream.Length;
int len = (int) (nextData - (dataPos + _dataSectionOffset));
BCLDebug.Assert(len >= 0 && len <= (int) _store.BaseStream.Length - dataPos + _dataSectionOffset, "Length was negative or outside the bounds of the file!");
// Read type code then byte[]
_store.BaseStream.Position = _dataSectionOffset + dataPos;
ResourceTypeCode typeCode = (ResourceTypeCode) _store.Read7BitEncodedInt();
resourceType = TypeNameFromTypeCode(typeCode);
// The length must be adjusted to subtract off the number
// of bytes in the 7 bit encoded type code.
len -= (int) (_store.BaseStream.Position - (_dataSectionOffset + dataPos));
byte[] bytes = _store.ReadBytes(len);
if (bytes.Length != len)
throw new FormatException(Environment.GetResourceString("BadImageFormat_ResourceNameCorrupted"));
resourceData = bytes;
}
}