将文件流式传输为字节并返回的正确术语
我有以下方法:
public static byte[] ConvertFileToBytes(string filePath)
{
var fInfo = new FileInfo(filePath);
var numBytes = fInfo.Length;
var dLen = Convert.ToDouble(fInfo.Length / 1000000);
var fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
var br = new BinaryReader(fStream);
var data = br.ReadBytes((int)numBytes);
br.Close();
fStream.Close();
fStream.Dispose();
return data;
}
public static void ConvertBytesToFile(byte[] file, string filePath)
{
var ms = new MemoryStream(file);
var fs = new FileStream(filePath, FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();
}
正确命名这些方法是什么?(因为 ConvertXXXtoYYY 只是不会将其剪切为实用程序库)
I have the below methods:
public static byte[] ConvertFileToBytes(string filePath)
{
var fInfo = new FileInfo(filePath);
var numBytes = fInfo.Length;
var dLen = Convert.ToDouble(fInfo.Length / 1000000);
var fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
var br = new BinaryReader(fStream);
var data = br.ReadBytes((int)numBytes);
br.Close();
fStream.Close();
fStream.Dispose();
return data;
}
public static void ConvertBytesToFile(byte[] file, string filePath)
{
var ms = new MemoryStream(file);
var fs = new FileStream(filePath, FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();
}
What is the correct to name these methods? (because ConvertXXXtoYYY just doesn't cut it in a Utilities library)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
WriteAllBytes 和 ReadAllBytes 是一个很好的建议,但要回答您的问题...
Save() 将是重命名 ConvertToFile() 和 Object.CreateFromFile() 的不错选择,相反。
The WriteAllBytes and ReadAllBytes are a good suggestion, but to answer your Question ...
Save() would be a good choice for renaming of ConvertToFile() and Object.CreateFromFile() for the reverse.
File.ReadAllBytes 和 File.WriteAllBytes ;)
How about File.ReadAllBytes and File.WriteAllBytes ;)
通常使用的术语是“序列化”和“反序列化”(有时是“编组”和“解组”)。
The terms usually used are "serialize" and "deserialize" (or sometimes "marshal" and "demarshal").
编组/解编组可能是合适的术语。
http://en.wikipedia.org/wiki/Marshalling_(computer_science)
Marshalling/Unmarshalling might be the appropriate term.
http://en.wikipedia.org/wiki/Marshalling_(computer_science)
在 C++ 中,它们被称为读和写。
In C++ they would be called read and write.