Elight.Utility/Files/FileUtil.cs

(开头部分) 17KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Reflection;
using Elight.Utility.Core;
using Elight.Utility.Other;
#if !NETFRAMEWORK
using Microsoft.AspNetCore.Http;
#endif
namespace Elight.Utility.Files
{
    /// <summary>
    /// 文件操作辅助类。
    /// </summary>
    public class FileUtil
    {
#if !NETFRAMEWORK
        public static void Save(IFormFile file, string filePath)
        {
            long size = 0;
            size += file.Length;
            using (FileStream fs = System.IO.File.Create(filePath))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
        }
#endif
        #region Stream、byte[] 和 文件之间的转换

        /// <summary>
        /// 将流读取到缓冲区中
        /// </summary>
        /// <param name="stream">原始流</param>
        public static byte[] StreamToBytes(Stream stream)
        {
            try
            {
                //创建缓冲区
                byte[] buffer = new byte[stream.Length];

                //读取流
                stream.Read(buffer, 0, Convert.ToInt32(stream.Length));

                //返回流
                return buffer;
            }
            catch (IOException ex)
            {
                throw ex;
            }
            finally
            {
                //关闭流
                stream.Close();
            }
        }

后面还有 503 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。