StreamHelper
public static MemoryStream CreateMemoryStreamFromBytes(byte[] inputData)
{
if (inputData == null || inputData.Length == 0)
{
return null;
}
MemoryStream result = new MemoryStream(inputData, false);
return result;
} /// <summary>
/// Read the data based on byte array from a specific file which path is from input.
/// </summary>
/// <param name="localFilePath">File path you want read.</param>
/// <returns>The file data based on byte array of input file. If input file path not exists, return null.</returns>
public static byte[] ReadBytesFromFile(string localFilePath)
{
if (StringHelper.IsNullOrEmpty(localFilePath)
|| !File.Exists(localFilePath))
{
return null;
}
FileStream fs = new FileStream(localFilePath,
FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] result = new byte[fs.Length];
int bufferSize = Convert.ToInt32((long)65536 > fs.Length ? fs.Length : (long)65536);
int offset = 0;
int readCount = 0;
using (fs as IDisposable)
{
while ((readCount = fs.Read(result, offset, bufferSize)) > 0)
{
offset += readCount;
bufferSize = bufferSize > result.Length - offset ?
result.Length - offset : bufferSize;
}
}
return result;
}
StreamHelper的更多相关文章
- Stream/Bytes[]/Image对象相互转化
Stream/Bytes[]/Image对象相互转化 Stream转Byte数组.Image转Byte数组.文件转Stream等 /// <summary> /// 将 Stream 转成 ...
- sream bytes[] img相互转换
/// <summary> /// 将 Stream 转成 byte[] /// </summary> /// <param name="stream" ...
- kindeditor修改图片上传路径-使用webapi上传图片到图片服务器
kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 在这里我着重介绍一些使用kindeditor修改图片上传路径并通过webapi上传图片到图片服务器的方案. 因为我使用的 ...
- kindeditor扩展粘贴图片功能&修改图片上传路径并通过webapi上传图片到图片服务器
前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...
- kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器
前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...
- IntraWeb XIV 类型速查表
tkClass ================== IWUserSessionBase.TIWUserSessionBase < TDataModule < TComponent < ...
- WPF ListView 简单的拖拽实现(转)
首先设置ListView的AllowDrop=True:SelectionMode=Extended;并且ListView视图为GridVIew. private void listView1_Mou ...
- .NET 2.0 参考源码索引
http://www.projky.com/dotnet/2.0/Microsoft/CSharp/csharpcodeprovider.cs.htmlhttp://www.projky.com/do ...
- springboot 快速开发的定制补充
增强 SpringBoot 快速开发工具 项目地址:https://gitee.com/sanri/web-ui 优点:这是一个 web 通用配置的组件,即插即用,可用于新项目或私活.是对 Sprin ...
随机推荐
- asp.net WebApi and protobuff
protobuff 是谷歌开发的,在性能上要比Json xml好很多,对性能要求比较高的时候这个是一个不错的选择,但是这个目前只是一个序列化反序列化的东西,以前原生的只有几种语言的现在在github ...
- 【转】 Nginx深入详解之多进程网络模型
[转自]http://blog.chinaunix.net/uid-22312037-id-3974068.html 一.进程模型 Nginx之所以为广大码农喜爱,除了其高性能外,还有其 ...
- 【情人节来一发】网站添加QQ客服功能
今年的元宵节遇到情人节,挺不自量力的,呵呵,开篇给各位讲个段子,早上一美女同学在空间发说说道:“开工大吉 起床啦,卖元宵,卖玫瑰,卖避孕套啦-有木有一起去发财的小伙伴?Let’s go…”,对于此种长 ...
- Python中的几种数据类型
大体上把Python中的数据类型分为如下几类: Number(数字) 包括int,long,float,complex String(字符串) 例如:hello,"hello" ...
- EF架构~CodeFirst模型下的数据初始化
回到目录 我为什么会来 在传统的大型系统设计中,数据库建模是个比开发更早的环节,先有数据库,然后是ORM模型,最后才是开发程序,而这种模型在EF出现后发生了转变,而且有可能将来会被code first ...
- atitit 短信接口规范与短信解决方案.docx
atitit 短信接口规范与短信解决方案.docx 1.1. 国内比较著名的短信提供商1 1.2. 短信接口规范1 1.3. 短信sdk构成1 1.4. 短信的实现1 1.5. SmsServiceY ...
- Atitit RSA非对称加密原理与解决方案
Atitit RSA非对称加密原理与解决方案 1.1. 一.一点历史 1 1.2. 八.加密和解密 2 1.3. 二.基于RSA的消息传递机制 3 1.4. 基于rsa的授权验证机器码 4 1.5. ...
- Atitit python3.0 3.3 3.5 3.6 新特性 Python2.7新特性1Python 3_x 新特性1python3.4新特性1python3.5新特性1值得关注的新特性1Pyth
Atitit python3.0 3.3 3.5 3.6 新特性 Python2.7新特性1 Python 3_x 新特性1 python3.4新特性1 python3.5新特性1 值得关注的新特性1 ...
- DOM_06之定时器、事件、cookie
1.定时器:①任务函数:函数结尾判断临界值:②启动定时器:a.周期性:timer=setInterval(任务函数,interval):b.一次性:timer=setTimeout(任务函数,wait ...
- Script Component 引用package variable
ScriptComponet 的变量分为两种类型,ReadOnly和ReadWrite,使用C#引用这两种类型的变量,有一点不同. 1,创建两个变量 2,将变量传递给script component ...