简体   繁体   English

大文件的Base64?

[英]Base64 for large files?

I'm working on a simple file and folder transfer program in c# using the tcp protocol. 我正在使用tcp协议在c#中开发一个简单的文件和文件夹传输程序。

The method I use to transfer a file is to divide it into small pieces. 我用来传输文件的方法是将其分成小块。 Each of these pieces will be encoded in Base64 and inserted into a more complex JSON message which will then be sent to the other side. 这些片段中的每一个都将在Base64中编码,并插入到更复杂的JSON消息中,然后将其发送到另一端。 So every message will always be in text form thanks to Base64. 因此,多亏了Base64,每条消息都将始终采用文本形式。

I don't have much experience with networks and I decided to make this choice because reading on the internet, sending a stream of bytes without any coding could risk that some part of the message could be interpreted by the router or firewall as a command risking interrupt the connection. 我没有太多的网络经验,所以我决定做出此选择,因为在Internet上阅读,发送未经任何编码的字节流可能会冒着路由器或防火墙将某些消息解释为命令的风险。中断连接。

My problem is that my software also works with very large files (> 10GB) and the base64 encoding only increases the data size and makes the transfer very slow because the cpu works so much to encode/decode continuously. 我的问题是我的软件还可以处理非常大的文件(> 10GB),而base64编码只会增加数据大小,并使传输速度非常慢,因为cpu在连续编码/解码方面起着很大作用。

Now I would like to know: 现在我想知道:

  • Is it true that for example, sending a simple file converted only in bytes without first being encoded in any format, risks causing a problem to the router or firewall? 例如,发送仅以字节为单位转换而未先以任何格式进行编码的简单文件是否会给路由器或防火墙带来问题,这是真的吗?
  • Is it correct to use Base64 for large file transfers? 使用Base64进行大文件传输是否正确?
  • Are there better alternatives? 有更好的选择吗?

Is it true that for example, sending a simple file converted only in bytes without first being encoded in any format, risks causing a problem to the router or firewall? 例如,发送仅以字节为单位转换而未先以任何格式进行编码的简单文件是否会给路由器或防火墙带来问题,这是真的吗?

Not at all. 一点也不。 It is perfectly normal to do, for example all that HTTPS communication is binary - and it works. 这样做是完全正常的,例如所有HTTPS通信都是二进制的-并且可以正常工作。

Is it correct to use Base64 for large file transfers? 使用Base64进行大文件传输是否正确?

While one can do this it is a useless overhead if the underlying layer supports binary data. 虽然可以做到这一点,但如果底层支持二进制数据,则将是无用的开销。

Are there better alternatives? 有更好的选择吗?

Use binary directly. 直接使用二进制文件。 Don't encode or decode anything. 不要编码或解码任何东西。 Don't wrap it into layers like JSON which are not actually needed for transfer. 不要将其包装到JSON这类实际上不需要传输的层中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM