Example #1
0
        /// <summary>
        /// 读取指定长度或者一直读取到结尾流内容到字节数组;
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static byte[] ReadStream(Stream fs, int length = Int32.MaxValue)
        {
            MemoryStream ms = new MemoryStream();

            StreamUtil.WriteStream(fs, ms, 0, length);
            return(ms.GetBuffer());
        }
Example #2
0
        /// <summary>
        /// 追加文件内容到给定的流中
        /// </summary>
        /// <param name="fs">目的文件流</param>
        /// <param name="srcFilePath">原文件,该文件内容追加到目的文件流中</param>
        public static void AppendFile(FileStream fs, string srcFilePath)
        {
            FileStream srcfs = File.Open(srcFilePath, FileMode.Open);

            StreamUtil.WriteStream(fs, srcfs);
            srcfs.Close();
        }
Example #3
0
 /// <summary>
 /// 将本片段流中的内容写出到给定的文件流中
 /// </summary>
 /// <param name="destStream"></param>
 /// <returns>返回成功写出的字节数量,因为目的流可能中断,所以必须返回成功写入的数据数量</returns>
 public int write(Stream destStream)
 {
     return(StreamUtil.WriteStream(destStream, stream, start, length));
 }