zoukankan      html  css  js  c++  java
  • filefunc.pas

    /// <author>cxg 2020-9-29</author>
    
    unit filefunc;
    
    interface
    
    uses
      Classes, ulog, serial, uGlobal, SysUtils;
    
    function downfile(const params: RawByteString): RawByteString;
    
    function upfile(const params: RawByteString): RawByteString;
    
    implementation
    
    function downfile(const params: RawByteString): RawByteString;
    var
      requ: TSerial;
      filename: string;
      fs: TFileStream;
    begin
      requ := TSerial.Create;
      fs := TFileStream.Create(DownPath + filename, fmOpenRead or fmShareExclusive);
      try
        try
          requ.loadFromRawByteString(params);
          filename := requ.force('filename').AsString;
          requ.clear;
          requ.force('return').AsBoolean := true;
          requ.force('file').AsStream := fs;
          Result := requ.saveToRawByteString;
        except
          on e: Exception do
          begin
            requ.clear;
            requ.force('return').AsBoolean := False;
            requ.force('err').AsString := e.Message;
            Result := requ.saveToRawByteString;
            Log.WriteLog('filefunc.downfile ' + e.Message);
          end;
        end;
      finally
        requ.Free;
        fs.Free;
      end;
    end;
    
    function upfile(const params: RawByteString): RawByteString;
    var
      requ: TSerial;
      filename: string;
      ms: TStream;
    begin
      requ := TSerial.Create;
      ms := TMemoryStream.Create;
      try
        try
          requ.loadFromRawByteString(params);
          filename := requ.force('filename').AsString;
          ForceDirectories(UpPath);
          ms := requ.force('file').AsStream;
          TMemoryStream(ms).SaveToFile(UpPath + filename);
          requ.clear;
          requ.force('return').AsBoolean := true;
          Result := requ.saveToRawByteString;
        except
          on e: Exception do
          begin
            requ.clear;
            requ.force('return').AsBoolean := False;
            Result := requ.saveToRawByteString;
            Log.WriteLog('filefunc.upfile ' + e.Message);
          end;
        end;  
      finally
        requ.Free;
        ms.Free;
      end;   
    end;
    
    end.
    

      

  • 相关阅读:
    Nginx 启用gzip压缩
    HTTP压缩的过程
    什么是HTTP压缩及HTTP压缩的过程
    Fiddler抓包工具总结
    HTTP内容编码和HTTP压缩的区别
    LINQ query on a DataTable
    C# Collection for "most recently used"
    Keep timer (setInterval) running while reloading page
    Is there a way to detect if a browser window is not currently active?
    Force Logout users if users are inactive for a certain period of time
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/13751283.html
Copyright © 2011-2022 走看看