private void ReadStreams(IBinaryAccessor accessor, long metadataOffset) { int numberOfStream = accessor.ReadUInt16(); int[] offsets = new int[numberOfStream]; int[] sizes = new int[numberOfStream]; string[] names = new string[numberOfStream]; for (int i = 0; i < numberOfStream; i++) { offsets[i] = accessor.ReadInt32(); sizes[i] = accessor.ReadInt32(); // Name of the stream; a zero-terminated ASCII string no longer than 31 characters (plus zero terminator). // The name might be shorter, in which case the size of the stream header is correspondingly reduced, // padded to the 4-byte boundary. long startPos = accessor.Position; names[i] = accessor.ReadNullTerminatedString(Encoding.ASCII); accessor.Align(startPos, 4); } int tableIndex = -1; for (int i = 0; i < numberOfStream; i++) { int offset = offsets[i]; int size = sizes[i]; string name = names[i]; if (name == MetadataConstants.StreamTable) { tableIndex = i; _tables.IsOptimized = true; } else if (name == MetadataConstants.StreamTableUnoptimized) { tableIndex = i; _tables.IsOptimized = false; } else if (name == MetadataConstants.StreamStrings) { accessor.Position = offset + metadataOffset; _strings.Blob = new Blob(accessor.ReadBytes(size)); } else if (name == MetadataConstants.StreamUserStrings) { accessor.Position = offset + metadataOffset; _userStrings.Blob = new Blob(accessor.ReadBytes(size)); } else if (name == MetadataConstants.StreamGuid) { accessor.Position = offset + metadataOffset; _guids.Blob = new Blob(accessor.ReadBytes(size)); } else if (name == MetadataConstants.StreamBlob) { accessor.Position = offset + metadataOffset; _blobs.Blob = new Blob(accessor.ReadBytes(size)); } else { accessor.Position = offset + metadataOffset; var stream = new MetadataExternalStream(name, new Blob(accessor.ReadBytes(size))); ExternalStreams.Add(stream); } } if (tableIndex >= 0) { // Read table last as it relies on heaps. accessor.Position = offsets[tableIndex] + metadataOffset; _tables.Read(accessor); } }
private void WriteExternalStream(MetadataExternalStream externalStream) { WriteStreamHeader(externalStream.Name, externalStream.Blob.Length); _blob.Write(ref _state.StreamPos, externalStream.Blob.GetBuffer(), 0, externalStream.Blob.Length); }