恩code的FileStream用C#采用base64 [英] Encode a FileStream to base64 with c#

查看:311
本文介绍了恩code的FileStream用C#采用base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何连接code /德code一个简单的字符串/从的base64

I know how to encode / decode a simple string to / from base64.

但我会怎样做,如果数据已经被写入的FileStream 对象。比方说,我只有到FileStream对象访问不pviously存储在它的原始数据的$ P $。如何将我带code一的FileStream为base64 之前,我刷新的FileStream到一个文件中。

But how would I do that if the data is already been written to a FileStream object. Let's say I have only access to the FileStream object not to the previously stored original data in it. How would I encode a FileStream to base64 before I flush the FileStream to a file.

OFC我可以打开我的文件和连接code /解code它,我已经写了的FileStream到文件后,但我想做到这一切在一个单一的步骤没有做两文件操作相继。该文件可以更大,它也将采取双倍的时间来加载,EN code和重新保存后,这是刚才保存前很短的时间。

Ofc I could just open my file and encode / decode it after I have written the FileStream to the file, but I would like to do this all in one single step without doing two file operations one after another. The file could be larger and it would also take double time to load, encode and save it again after it was just saved a short time before.

也许你们有人知道一个更好的解决方案?我可以因此FileStream转换为字符串,连接code中的字符串,然后转换成字符串回一个FileStream例如或者该怎么办怎么会出现这样的code样子?

Maybe someone of you knows a better solution? Can I convert the FileStream to a string, encode the string and then convert the string back to a FileStream for example or what would I do and how would such a code look like?

推荐答案

您也可以连接code字节Base64编码。如何从流得到这个在这里看到:如何转换的流成一个byte []在C#中?

You can also encode bytes to Base64. How to get this from a stream see here: How to convert an Stream into a byte[] in C#?

或者我想这应该也是可以使用的ToString()方法和连接code这一点。

Or I think it should be also possible to use the .ToString() method and encode this.

这篇关于恩code的FileStream用C#采用base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆