GZipStream: why do we convert to base 64 after compression?

北战南征 提交于 2019-12-06 03:52:28

Most likely the base 64 string is so that it can be viewed as plain text, for example for printing, including in an email or something like that. Edit: Now I see the source, they say they want to insert it in an XML file, so that is why they needed to be plain text.

The compressed.Length + 4 size is required because of the next line - BlockCopy. It starts copying from 4 bytes into the gzBuffer. (The 4th argument is the byte offset into the destination buffer). The second BlockCopy is putting the length of the compressed string into the first four bytes of the destination buffer. I'm not sure why it would need the length here, but there may well be a corresponding decode routine it has to line up with.

Edit: The length is used in the decompression routine so that the program knows how long the decompressed byte buffer should be.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!