TagTool.Cache.TagCache.SetTagDataRaw C# (CSharp) Method

SetTagDataRaw() public method

Overwrites a tag's raw data, including its header.
tag
public SetTagDataRaw ( Stream stream, TagInstance tag, byte data ) : void
stream Stream The stream to write to.
tag TagTool.TagGroups.TagInstance The tag to overwrite.
data byte The data to overwrite the tag with.
return void
        public void SetTagDataRaw(Stream stream, TagInstance tag, byte[] data)
        {
            if (tag == null)
                throw new ArgumentNullException(nameof(tag));

            // Ensure the data fits
            if (tag.HeaderOffset < 0)
                tag.HeaderOffset = GetNewTagOffset(tag.Index);
            ResizeBlock(stream, tag, tag.HeaderOffset, tag.TotalSize, data.Length);
            tag.TotalSize = data.Length;

            // Write the data
            stream.Position = tag.HeaderOffset;
            stream.Write(data, 0, data.Length);

            // Re-parse it
            stream.Position = tag.HeaderOffset;
            tag.ReadHeader(new BinaryReader(stream));
            UpdateTagOffsets(new BinaryWriter(stream));
        }