LumiSoft.Net.Core.QuotedPrintableDecodeB C# (CSharp) Method

QuotedPrintableDecodeB() public static method

quoted-printable decoder.
public static QuotedPrintableDecodeB ( byte data, bool includeCRLF ) : byte[]
data byte Data which to encode.
includeCRLF bool Specified if line breaks are included or skipped. For text data CRLF is usually included and for binary data excluded.
return byte[]
        public static byte[] QuotedPrintableDecodeB(byte[] data,bool includeCRLF)
        {
            MemoryStream strm = new MemoryStream(data);
            MemoryStream dStrm = new MemoryStream();

            int b = strm.ReadByte();
            while(b > -1){
                // Hex eg. =E4
                if(b == '='){
                    byte[] buf = new byte[2];
                    strm.Read(buf,0,2);

                    // <CRLF> followed by =, it's splitted line
                    if(!(buf[0] == '\r' && buf[1] == '\n')){
                        try{
                            byte[] convertedByte = FromHex(buf);
                            dStrm.Write(convertedByte,0,convertedByte.Length);
                        }
                        catch{ // If worng hex value, just skip this chars
                        }
                    }
                }
                else{
                    // For text line breaks are included, for binary data they are excluded

                    if(includeCRLF){
                        dStrm.WriteByte((byte)b);
                    }
                    else{
                        // Skip \r\n they must be escaped
                        if(b != '\r' && b != '\n'){
                            dStrm.WriteByte((byte)b);
                        }
                    }
                }

                b = strm.ReadByte();
            }

            return dStrm.ToArray();
        }