Recurity.Swf.SwfFile.FixIncorrectStreamSize C# (CSharp) Method

FixIncorrectStreamSize() private method

Fixes the incorrect stream size by changing the length of a stream and dumping all data that do not fit into it.
private FixIncorrectStreamSize ( Stream s, long l ) : void
s Stream The stream that will be fixed
l long The new length of the stream
return void
        private void FixIncorrectStreamSize(Stream s, long l)
        {
            byte[] b = new byte[l];

            long position = s.Position;
            s.Seek(0, SeekOrigin.Begin);

            if (s.Length >= l)
            {
                s.Read(b, 0, (int)l);
            }
            else
            {
                s.Read(b, 0, (int)s.Length);
            }

            MemoryStream newStream = new MemoryStream(b);
            s = newStream;
            s.Seek(position, SeekOrigin.Begin);
        }